Skip to content

Commit

Permalink
fix(fe): 🐛 setting discord options not work
Browse files Browse the repository at this point in the history
  • Loading branch information
lehuygiang28 committed Aug 22, 2024
1 parent 2fdcf95 commit 354fd7b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions apps/fe/src/components/form-item/task-form-item/alert-option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ export type AlertOptionsProps = Readonly<{
}>;

export function AlertOptions({ control, errors, setValue }: AlertOptionsProps) {
const [showDiscordOptions, setShowDiscordOptions] = useState(false);
const [showDiscordOptions, setShowDiscordOptions] = useState<boolean | null>(null);

useEffect(() => {
const dmUserId = control._formValues.options?.alert?.alertOn?.discord?.dmUserId;
const channelId = control._formValues.options?.alert?.alertOn?.discord?.channelId;

if (dmUserId || channelId) {
setValue('options.alert.alertOn.discord.dmUserId', dmUserId);
setValue('options.alert.alertOn.discord.channelId', channelId);
setShowDiscordOptions(true);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [control._formValues.options?.alert?.alertOn?.discord, setValue]);

useEffect(() => {
if (!showDiscordOptions) {
if (showDiscordOptions === false) {
setValue('options.alert.alertOn.discord.dmUserId', '');
setValue('options.alert.alertOn.discord.channelId', '');
}
Expand Down Expand Up @@ -123,6 +125,8 @@ export function AlertOptions({ control, errors, setValue }: AlertOptionsProps) {
noStyle
>
<Input
{...field}
value={field?.value?.toString() ?? ''}
addonBefore="Send a Direct Message on Discord to user ID:"
defaultValue={field?.value?.toString() ?? ''}
/>
Expand Down Expand Up @@ -151,6 +155,8 @@ export function AlertOptions({ control, errors, setValue }: AlertOptionsProps) {
noStyle
>
<Input
{...field}
value={field?.value?.toString() ?? ''}
addonBefore="Send message on Discord to channel ID:"
defaultValue={field?.value?.toString() ?? ''}
/>
Expand Down

0 comments on commit 354fd7b

Please sign in to comment.