2022-07-18 10:47:54 +02:00
|
|
|
|
import * as React from 'react';
|
2022-07-22 16:50:36 +02:00
|
|
|
|
import { useForm, SubmitHandler } from 'react-hook-form';
|
2022-07-18 10:47:54 +02:00
|
|
|
|
import I18n from 'i18n-js';
|
|
|
|
|
|
|
|
|
|
|
|
import Box from '../../common/Box';
|
|
|
|
|
|
import SiteSettingsInfoBox from '../../common/SiteSettingsInfoBox';
|
|
|
|
|
|
import Button from '../../common/Button';
|
|
|
|
|
|
import HttpStatus from '../../../constants/http_status';
|
|
|
|
|
|
import {
|
2023-02-04 15:43:15 +01:00
|
|
|
|
TENANT_SETTING_BRAND_DISPLAY_NAME_AND_LOGO,
|
|
|
|
|
|
TENANT_SETTING_BRAND_DISPLAY_NAME_ONLY,
|
|
|
|
|
|
TENANT_SETTING_BRAND_DISPLAY_LOGO_ONLY,
|
|
|
|
|
|
TENANT_SETTING_BRAND_DISPLAY_NONE,
|
2023-02-11 11:35:27 +01:00
|
|
|
|
TENANT_SETTING_COLLAPSE_BOARDS_IN_HEADER_NO_COLLAPSE,
|
|
|
|
|
|
TENANT_SETTING_COLLAPSE_BOARDS_IN_HEADER_ALWAYS_COLLAPSE,
|
2023-02-04 15:43:15 +01:00
|
|
|
|
} from '../../../interfaces/ITenantSetting';
|
2023-02-05 11:55:38 +01:00
|
|
|
|
import { DangerText, SmallMutedText } from '../../common/CustomTexts';
|
2022-08-05 18:15:17 +02:00
|
|
|
|
import { getLabel, getValidationMessage } from '../../../helpers/formUtils';
|
2023-02-05 11:55:38 +01:00
|
|
|
|
import IBoardJSON from '../../../interfaces/json/IBoard';
|
2024-03-24 12:54:02 +01:00
|
|
|
|
import ActionLink from '../../common/ActionLink';
|
|
|
|
|
|
import { LearnMoreIcon } from '../../common/Icons';
|
2022-07-22 16:50:36 +02:00
|
|
|
|
|
|
|
|
|
|
export interface ISiteSettingsGeneralForm {
|
|
|
|
|
|
siteName: string;
|
|
|
|
|
|
siteLogo: string;
|
|
|
|
|
|
brandDisplaySetting: string;
|
|
|
|
|
|
locale: string;
|
2023-02-05 11:55:38 +01:00
|
|
|
|
showVoteCount: boolean;
|
|
|
|
|
|
showVoteButtonInBoard: boolean;
|
2024-02-27 18:32:14 +01:00
|
|
|
|
showPoweredBy: boolean;
|
2023-02-05 11:55:38 +01:00
|
|
|
|
rootBoardId?: string;
|
2024-03-24 12:54:02 +01:00
|
|
|
|
customDomain?: string;
|
2023-02-11 11:35:27 +01:00
|
|
|
|
showRoadmapInHeader: boolean;
|
|
|
|
|
|
collapseBoardsInHeader: string;
|
2022-07-22 16:50:36 +02:00
|
|
|
|
}
|
2022-07-18 10:47:54 +02:00
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
|
originForm: ISiteSettingsGeneralForm;
|
2023-02-05 11:55:38 +01:00
|
|
|
|
boards: IBoardJSON[];
|
2024-03-28 12:29:54 +01:00
|
|
|
|
isMultiTenant: boolean;
|
2022-07-18 10:47:54 +02:00
|
|
|
|
authenticityToken: string;
|
|
|
|
|
|
|
|
|
|
|
|
areUpdating: boolean;
|
|
|
|
|
|
error: string;
|
|
|
|
|
|
|
|
|
|
|
|
updateTenant(
|
|
|
|
|
|
siteName: string,
|
|
|
|
|
|
siteLogo: string,
|
|
|
|
|
|
brandDisplaySetting: string,
|
|
|
|
|
|
locale: string,
|
2023-02-05 11:55:38 +01:00
|
|
|
|
rootBoardId: number,
|
2024-03-24 12:54:02 +01:00
|
|
|
|
customDomain: string,
|
2023-02-11 11:35:27 +01:00
|
|
|
|
showRoadmapInHeader: boolean,
|
|
|
|
|
|
collapseBoardsInHeader: string,
|
2023-02-05 11:55:38 +01:00
|
|
|
|
showVoteCount: boolean,
|
|
|
|
|
|
showVoteButtonInBoard: boolean,
|
2024-02-27 18:32:14 +01:00
|
|
|
|
showPoweredBy: boolean,
|
2022-07-18 10:47:54 +02:00
|
|
|
|
authenticityToken: string
|
|
|
|
|
|
): Promise<any>;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-22 16:50:36 +02:00
|
|
|
|
const GeneralSiteSettingsP = ({
|
|
|
|
|
|
originForm,
|
2023-02-05 11:55:38 +01:00
|
|
|
|
boards,
|
2024-03-28 12:29:54 +01:00
|
|
|
|
isMultiTenant,
|
2022-07-22 16:50:36 +02:00
|
|
|
|
authenticityToken,
|
|
|
|
|
|
|
|
|
|
|
|
areUpdating,
|
|
|
|
|
|
error,
|
|
|
|
|
|
updateTenant,
|
|
|
|
|
|
}: Props) => {
|
|
|
|
|
|
const {
|
|
|
|
|
|
register,
|
|
|
|
|
|
handleSubmit,
|
2024-03-24 12:54:02 +01:00
|
|
|
|
formState: { isDirty, isSubmitSuccessful, errors },
|
|
|
|
|
|
watch,
|
2022-07-22 16:50:36 +02:00
|
|
|
|
} = useForm<ISiteSettingsGeneralForm>({
|
|
|
|
|
|
defaultValues: {
|
|
|
|
|
|
siteName: originForm.siteName,
|
|
|
|
|
|
siteLogo: originForm.siteLogo,
|
|
|
|
|
|
brandDisplaySetting: originForm.brandDisplaySetting,
|
|
|
|
|
|
locale: originForm.locale,
|
2023-02-05 11:55:38 +01:00
|
|
|
|
showVoteCount: originForm.showVoteCount,
|
|
|
|
|
|
showVoteButtonInBoard: originForm.showVoteButtonInBoard,
|
2024-02-27 18:32:14 +01:00
|
|
|
|
showPoweredBy: originForm.showPoweredBy,
|
2023-02-05 11:55:38 +01:00
|
|
|
|
rootBoardId: originForm.rootBoardId,
|
2024-03-24 12:54:02 +01:00
|
|
|
|
customDomain: originForm.customDomain,
|
2023-02-11 11:35:27 +01:00
|
|
|
|
showRoadmapInHeader: originForm.showRoadmapInHeader,
|
|
|
|
|
|
collapseBoardsInHeader: originForm.collapseBoardsInHeader,
|
2022-07-22 16:50:36 +02:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const onSubmit: SubmitHandler<ISiteSettingsGeneralForm> = data => {
|
|
|
|
|
|
updateTenant(
|
|
|
|
|
|
data.siteName,
|
|
|
|
|
|
data.siteLogo,
|
|
|
|
|
|
data.brandDisplaySetting,
|
|
|
|
|
|
data.locale,
|
2023-02-05 11:55:38 +01:00
|
|
|
|
Number(data.rootBoardId),
|
2024-03-24 12:54:02 +01:00
|
|
|
|
data.customDomain,
|
2023-02-11 11:35:27 +01:00
|
|
|
|
data.showRoadmapInHeader,
|
|
|
|
|
|
data.collapseBoardsInHeader,
|
2023-02-05 11:55:38 +01:00
|
|
|
|
data.showVoteCount,
|
|
|
|
|
|
data.showVoteButtonInBoard,
|
2024-02-27 18:32:14 +01:00
|
|
|
|
data.showPoweredBy,
|
2023-02-11 11:35:27 +01:00
|
|
|
|
authenticityToken
|
2022-07-18 10:47:54 +02:00
|
|
|
|
).then(res => {
|
|
|
|
|
|
if (res?.status !== HttpStatus.OK) return;
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
|
});
|
2022-07-22 16:50:36 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-24 12:54:02 +01:00
|
|
|
|
const customDomain = watch('customDomain');
|
|
|
|
|
|
|
2022-07-22 16:50:36 +02:00
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Box>
|
|
|
|
|
|
<h2>{ I18n.t('site_settings.general.title') }</h2>
|
|
|
|
|
|
|
|
|
|
|
|
<form onSubmit={handleSubmit(onSubmit)}>
|
|
|
|
|
|
<div className="formRow">
|
|
|
|
|
|
<div className="formGroup col-4">
|
2022-08-05 18:15:17 +02:00
|
|
|
|
<label htmlFor="siteName">{ getLabel('tenant', 'site_name') }</label>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
<input
|
|
|
|
|
|
{...register('siteName', { required: true })}
|
|
|
|
|
|
id="siteName"
|
|
|
|
|
|
className="formControl"
|
|
|
|
|
|
/>
|
2022-08-05 18:15:17 +02:00
|
|
|
|
<DangerText>{errors.siteName && getValidationMessage(errors.siteName.type, 'tenant', 'site_name')}</DangerText>
|
2022-07-18 10:47:54 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2022-07-22 16:50:36 +02:00
|
|
|
|
<div className="formGroup col-4">
|
2022-08-05 18:15:17 +02:00
|
|
|
|
<label htmlFor="siteLogo">{ getLabel('tenant', 'site_logo') }</label>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
<input
|
|
|
|
|
|
{...register('siteLogo')}
|
2024-05-09 19:23:45 +02:00
|
|
|
|
placeholder='https://example.com/logo.png'
|
2022-07-22 16:50:36 +02:00
|
|
|
|
id="siteLogo"
|
|
|
|
|
|
className="formControl"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="formGroup col-4">
|
2023-02-05 11:55:38 +01:00
|
|
|
|
<label htmlFor="brandSetting">{ getLabel('tenant_setting', 'brand_display') }</label>
|
2022-07-18 10:47:54 +02:00
|
|
|
|
<select
|
2022-07-22 16:50:36 +02:00
|
|
|
|
{...register('brandDisplaySetting')}
|
|
|
|
|
|
id="brandSetting"
|
2022-07-18 10:47:54 +02:00
|
|
|
|
className="selectPicker"
|
|
|
|
|
|
>
|
2023-02-04 15:43:15 +01:00
|
|
|
|
<option value={TENANT_SETTING_BRAND_DISPLAY_NAME_AND_LOGO}>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
{ I18n.t('site_settings.general.brand_setting_both') }
|
|
|
|
|
|
</option>
|
2023-02-04 15:43:15 +01:00
|
|
|
|
<option value={TENANT_SETTING_BRAND_DISPLAY_NAME_ONLY}>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
{ I18n.t('site_settings.general.brand_setting_name') }
|
|
|
|
|
|
</option>
|
2023-02-04 15:43:15 +01:00
|
|
|
|
<option value={TENANT_SETTING_BRAND_DISPLAY_LOGO_ONLY}>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
{ I18n.t('site_settings.general.brand_setting_logo') }
|
|
|
|
|
|
</option>
|
2023-02-04 15:43:15 +01:00
|
|
|
|
<option value={TENANT_SETTING_BRAND_DISPLAY_NONE}>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
{ I18n.t('site_settings.general.brand_setting_none') }
|
|
|
|
|
|
</option>
|
2022-07-18 10:47:54 +02:00
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="formGroup">
|
2022-08-05 18:15:17 +02:00
|
|
|
|
<label htmlFor="locale">{ getLabel('tenant', 'locale') }</label>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
<select
|
|
|
|
|
|
{...register('locale')}
|
|
|
|
|
|
id="locale"
|
|
|
|
|
|
className="selectPicker"
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value="en">🇬🇧 English</option>
|
|
|
|
|
|
<option value="it">🇮🇹 Italiano</option>
|
2022-07-23 13:58:14 +02:00
|
|
|
|
<option value="de">🇩🇪 Deutsch</option>
|
2022-07-25 15:47:10 +02:00
|
|
|
|
<option value="fr">🇫🇷 Français</option>
|
2024-01-06 17:13:56 +01:00
|
|
|
|
<option value="es">🇪🇸 Español</option>
|
2024-05-11 15:20:16 +02:00
|
|
|
|
<option value="pt-BR">🇵🇹🇧🇷 Português (Brasileiro)</option>
|
2024-03-15 00:14:31 +01:00
|
|
|
|
<option value="zh-CN">🇨🇳 中文</option>
|
2022-09-22 14:20:11 +02:00
|
|
|
|
<option value="ru">🇷🇺 Русский</option>
|
2024-01-08 23:13:39 +07:00
|
|
|
|
<option value="vi">🇻🇳 Tiếng Việt</option>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
2022-07-18 10:47:54 +02:00
|
|
|
|
|
2023-02-05 11:55:38 +01:00
|
|
|
|
<div className="formGroup">
|
|
|
|
|
|
<label htmlFor="rootBoardId">{ getLabel('tenant_setting', 'root_board_id') }</label>
|
|
|
|
|
|
<select
|
|
|
|
|
|
{...register('rootBoardId')}
|
|
|
|
|
|
id="rootBoardId"
|
|
|
|
|
|
className="selectPicker"
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value="0">
|
|
|
|
|
|
{I18n.t('roadmap.title')}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
<optgroup label={getLabel('board')}>
|
|
|
|
|
|
{boards.map((board, i) => (
|
|
|
|
|
|
<option value={board.id} key={i}>{board.name}</option>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</optgroup>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2024-03-28 12:29:54 +01:00
|
|
|
|
{ isMultiTenant &&
|
|
|
|
|
|
<div className="formGroup">
|
|
|
|
|
|
<label htmlFor="customDomain">{ getLabel('tenant', 'custom_domain') }</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
{...register('customDomain')}
|
|
|
|
|
|
id="customDomain"
|
|
|
|
|
|
className="formControl"
|
|
|
|
|
|
/>
|
|
|
|
|
|
{
|
|
|
|
|
|
originForm.customDomain !== customDomain && customDomain !== '' &&
|
|
|
|
|
|
<div style={{marginTop: 16}}>
|
|
|
|
|
|
<SmallMutedText>
|
|
|
|
|
|
{ I18n.t('site_settings.general.custom_domain_help', { domain: customDomain }) }
|
|
|
|
|
|
</SmallMutedText>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
<div style={{marginTop: 8}}>
|
2024-03-24 12:54:02 +01:00
|
|
|
|
<ActionLink
|
|
|
|
|
|
onClick={() => window.open('https://docs.astuto.io/custom-domain', '_blank')}
|
|
|
|
|
|
icon={<LearnMoreIcon />}
|
|
|
|
|
|
>
|
|
|
|
|
|
{I18n.t('site_settings.general.custom_domain_learn_more')}
|
|
|
|
|
|
</ActionLink>
|
|
|
|
|
|
</div>
|
2024-03-28 12:29:54 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
}
|
2024-03-24 12:54:02 +01:00
|
|
|
|
|
2023-02-05 11:55:38 +01:00
|
|
|
|
<br />
|
2023-02-11 11:35:27 +01:00
|
|
|
|
<h4>{ I18n.t('site_settings.general.subtitle_header') }</h4>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="formGroup">
|
|
|
|
|
|
<div className="checkboxSwitch">
|
|
|
|
|
|
<input {...register('showRoadmapInHeader')} type="checkbox" id="show_roadmap_in_header" />
|
|
|
|
|
|
<label htmlFor="show_roadmap_in_header">{ getLabel('tenant_setting', 'show_roadmap_in_header') }</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
<div className="formGroup">
|
|
|
|
|
|
<label htmlFor="collapseBoardsInHeader">{ getLabel('tenant_setting', 'collapse_boards_in_header') }</label>
|
|
|
|
|
|
<select
|
|
|
|
|
|
{...register('collapseBoardsInHeader')}
|
|
|
|
|
|
id="collapseBoardsInHeader"
|
|
|
|
|
|
className="selectPicker"
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value={TENANT_SETTING_COLLAPSE_BOARDS_IN_HEADER_NO_COLLAPSE}>
|
|
|
|
|
|
{ I18n.t('site_settings.general.collapse_boards_in_header_no_collapse') }
|
|
|
|
|
|
</option>
|
|
|
|
|
|
<option value={TENANT_SETTING_COLLAPSE_BOARDS_IN_HEADER_ALWAYS_COLLAPSE}>
|
|
|
|
|
|
{ I18n.t('site_settings.general.collapse_boards_in_header_always_collapse') }
|
|
|
|
|
|
</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
<h4>{ I18n.t('site_settings.general.subtitle_visibility') }</h4>
|
2023-02-05 11:55:38 +01:00
|
|
|
|
|
|
|
|
|
|
<div className="formGroup">
|
|
|
|
|
|
<div className="checkboxSwitch">
|
|
|
|
|
|
<input {...register('showVoteCount')} type="checkbox" id="show_vote_count_checkbox" />
|
|
|
|
|
|
<label htmlFor="show_vote_count_checkbox">{ getLabel('tenant_setting', 'show_vote_count') }</label>
|
|
|
|
|
|
<SmallMutedText>
|
|
|
|
|
|
{ I18n.t('site_settings.general.show_vote_count_help') }
|
|
|
|
|
|
</SmallMutedText>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
<div className="formGroup">
|
|
|
|
|
|
<div className="checkboxSwitch">
|
|
|
|
|
|
<input {...register('showVoteButtonInBoard')} type="checkbox" id="show_vote_button_in_board_checkbox" />
|
|
|
|
|
|
<label htmlFor="show_vote_button_in_board_checkbox">{ getLabel('tenant_setting', 'show_vote_button_in_board') }</label>
|
|
|
|
|
|
<SmallMutedText>
|
|
|
|
|
|
{ I18n.t('site_settings.general.show_vote_button_in_board_help') }
|
|
|
|
|
|
</SmallMutedText>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2022-07-18 10:47:54 +02:00
|
|
|
|
<br />
|
|
|
|
|
|
|
2024-02-27 18:32:14 +01:00
|
|
|
|
<div className="formGroup">
|
|
|
|
|
|
<div className="checkboxSwitch">
|
|
|
|
|
|
<input {...register('showPoweredBy')} type="checkbox" id="show_powered_by_checkbox" />
|
|
|
|
|
|
<label htmlFor="show_powered_by_checkbox">{ getLabel('tenant_setting', 'show_powered_by') }</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
2022-07-22 16:50:36 +02:00
|
|
|
|
<Button onClick={() => null} disabled={!isDirty}>
|
|
|
|
|
|
{I18n.t('common.buttons.update')}
|
2022-07-18 10:47:54 +02:00
|
|
|
|
</Button>
|
2022-07-22 16:50:36 +02:00
|
|
|
|
</form>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
|
|
<SiteSettingsInfoBox
|
|
|
|
|
|
areUpdating={areUpdating}
|
|
|
|
|
|
error={error}
|
|
|
|
|
|
areDirty={isDirty && !isSubmitSuccessful}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
2022-07-18 10:47:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-08 23:13:39 +07:00
|
|
|
|
export default GeneralSiteSettingsP;
|