-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fe): ⚡ update task form alert options for notifications
- Loading branch information
1 parent
91c3e98
commit b817239
Showing
5 changed files
with
176 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './task-form-item'; |
168 changes: 168 additions & 0 deletions
168
apps/fe/src/components/form-item/task-form-item/alert-option.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import { Divider, Space, Form, Checkbox, Input, Typography, Alert } from 'antd'; | ||
import { Control, Controller, FieldErrors, UseFormSetValue } from 'react-hook-form'; | ||
import { useState, useEffect } from 'react'; | ||
|
||
import { TaskFormValues } from '~/components/form/task-form'; | ||
|
||
const { Item } = Form; | ||
|
||
export function AlertOptions({ | ||
control, | ||
errors, | ||
setValue, | ||
}: { | ||
control: Control<TaskFormValues, NonNullable<unknown>>; | ||
errors: FieldErrors<TaskFormValues>; | ||
setValue: UseFormSetValue<TaskFormValues>; | ||
}) { | ||
const [showDiscordOptions, setShowDiscordOptions] = useState(false); | ||
|
||
useEffect(() => { | ||
const dmUserId = control._formValues.options?.alert?.alertOn?.discord?.dmUserId; | ||
const channelId = control._formValues.options?.alert?.alertOn?.discord?.channelId; | ||
if (dmUserId || channelId) { | ||
setShowDiscordOptions(true); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!showDiscordOptions) { | ||
setValue('options.alert.alertOn.discord.dmUserId', ''); | ||
setValue('options.alert.alertOn.discord.channelId', ''); | ||
} | ||
}, [showDiscordOptions, setValue]); | ||
|
||
return ( | ||
<> | ||
<Divider orientation="left">Notify me when</Divider> | ||
<Space direction="vertical"> | ||
<Controller<TaskFormValues> | ||
name={'options.alert.jobExecutionFailed'} | ||
control={control} | ||
render={({ field }) => ( | ||
<Item {...field} noStyle> | ||
<Checkbox {...field} checked={field?.value == true}> | ||
Job execution failed | ||
</Checkbox> | ||
</Item> | ||
)} | ||
/> | ||
<Controller<TaskFormValues> | ||
name={'options.alert.disableByTooManyFailures'} | ||
control={control} | ||
render={({ field }) => ( | ||
<Item {...field} noStyle> | ||
<Checkbox {...field} checked={field?.value == true}> | ||
Job is disabled by too many failures | ||
</Checkbox> | ||
</Item> | ||
)} | ||
/> | ||
</Space> | ||
<Divider orientation="left">Notify me on:</Divider> | ||
<Space direction="vertical"> | ||
<Controller<TaskFormValues> | ||
name={'options.alert.alertOn.email'} | ||
control={control} | ||
render={({ field }) => ( | ||
<Item {...field} noStyle> | ||
<Checkbox {...field} checked={field?.value == true}> | ||
</Checkbox> | ||
</Item> | ||
)} | ||
/> | ||
<Checkbox | ||
checked={showDiscordOptions} | ||
onChange={(e) => setShowDiscordOptions(e.target.checked)} | ||
> | ||
Discord | ||
</Checkbox> | ||
{showDiscordOptions && ( | ||
<> | ||
<Alert | ||
message={ | ||
<> | ||
To receive Discord notifications, please make sure our bot is | ||
allowed to send messages to you.{' '} | ||
<Typography.Link | ||
href={ | ||
process.env.NEXT_DISCORD_APP_AUTHORIZE_URL ?? | ||
'https://discord.com/oauth2/authorize?client_id=1276071272467660881' | ||
} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Click here | ||
</Typography.Link>{' '} | ||
to authorize. | ||
</> | ||
} | ||
type="info" | ||
showIcon | ||
/> | ||
<Space direction="vertical"> | ||
<Controller<TaskFormValues> | ||
name={'options.alert.alertOn.discord.dmUserId'} | ||
control={control} | ||
render={({ field: { ref, ...field } }) => ( | ||
<Item | ||
{...field} | ||
validateStatus={ | ||
errors?.options?.alert?.alertOn?.discord?.dmUserId | ||
? 'error' | ||
: 'validating' | ||
} | ||
help={ | ||
<> | ||
{ | ||
errors?.options?.alert?.alertOn?.discord | ||
?.dmUserId?.message | ||
} | ||
</> | ||
} | ||
noStyle | ||
> | ||
<Input | ||
addonBefore="Send a Direct Message on Discord to user ID:" | ||
defaultValue={field?.value?.toString() ?? ''} | ||
/> | ||
</Item> | ||
)} | ||
/> | ||
<Controller<TaskFormValues> | ||
name={'options.alert.alertOn.discord.channelId'} | ||
control={control} | ||
render={({ field: { ref, ...field } }) => ( | ||
<Item | ||
{...field} | ||
validateStatus={ | ||
errors?.options?.alert?.alertOn?.discord?.channelId | ||
? 'error' | ||
: 'validating' | ||
} | ||
help={ | ||
<> | ||
{ | ||
errors?.options?.alert?.alertOn?.discord | ||
?.channelId?.message | ||
} | ||
</> | ||
} | ||
noStyle | ||
> | ||
<Input | ||
addonBefore="Send message on Discord to channel ID:" | ||
defaultValue={field?.value?.toString() ?? ''} | ||
/> | ||
</Item> | ||
)} | ||
/> | ||
</Space> | ||
</> | ||
)} | ||
</Space> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './alert-option'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters