feat: discord notifications & notify by default
This commit is contained in:
parent
36faaf0b97
commit
5bb5c8a907
7 changed files with 164 additions and 14 deletions
|
@ -85,10 +85,14 @@ const ChoreEdit = () => {
|
|||
const [thingTrigger, setThingTrigger] = useState(null)
|
||||
const [isThingValid, setIsThingValid] = useState(false)
|
||||
|
||||
const [notificationMetadata, setNotificationMetadata] = useState({})
|
||||
const [notificationMetadata, setNotificationMetadata] = useState({
|
||||
dueDate: true,
|
||||
predue: true,
|
||||
nagging: true
|
||||
})
|
||||
|
||||
const [isRolling, setIsRolling] = useState(false)
|
||||
const [isNotificable, setIsNotificable] = useState(false)
|
||||
const [isNotificable, setIsNotificable] = useState(true)
|
||||
const [isActive, setIsActive] = useState(true)
|
||||
const [updatedBy, setUpdatedBy] = useState(0)
|
||||
const [createdBy, setCreatedBy] = useState(0)
|
||||
|
@ -710,7 +714,7 @@ const ChoreEdit = () => {
|
|||
onChange={e => {
|
||||
setIsNotificable(e.target.checked)
|
||||
}}
|
||||
defaultChecked={isNotificable}
|
||||
defaultChecked={true}
|
||||
checked={isNotificable}
|
||||
value={isNotificable}
|
||||
disabled={!isPlusAccount(userProfile)}
|
||||
|
|
|
@ -98,6 +98,10 @@ const NotificationSetting = () => {
|
|||
const [chatID, setChatID] = useState(
|
||||
userProfile?.notification_target?.target_id,
|
||||
)
|
||||
const [webhookURL, setWebhookURL] = useState(
|
||||
userProfile?.notification_target?.target_id,
|
||||
)
|
||||
|
||||
const [error, setError] = useState('')
|
||||
const SaveValidation = () => {
|
||||
switch (notificationTarget) {
|
||||
|
@ -116,6 +120,12 @@ const NotificationSetting = () => {
|
|||
return false
|
||||
}
|
||||
break
|
||||
case '4':
|
||||
if (webhookURL === '') {
|
||||
setError('Webhook URL is required')
|
||||
return false
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
@ -126,7 +136,8 @@ const NotificationSetting = () => {
|
|||
if (!SaveValidation()) return
|
||||
|
||||
UpdateNotificationTarget({
|
||||
target: chatID,
|
||||
// 4 = Discord
|
||||
target: notificationTarget === '4' ? webhookURL : chatID,
|
||||
type: Number(notificationTarget),
|
||||
}).then(resp => {
|
||||
if (resp.status != 200) {
|
||||
|
@ -134,13 +145,26 @@ const NotificationSetting = () => {
|
|||
return
|
||||
}
|
||||
|
||||
setUserProfile({
|
||||
...userProfile,
|
||||
notification_target: {
|
||||
target: chatID,
|
||||
type: Number(notificationTarget),
|
||||
},
|
||||
})
|
||||
// Discord
|
||||
if (notificationTarget === '4') {
|
||||
setUserProfile({
|
||||
...userProfile,
|
||||
notification_target: {
|
||||
target: webhookURL,
|
||||
type: Number(notificationTarget),
|
||||
},
|
||||
})
|
||||
} else {
|
||||
// Others (Telegram)
|
||||
setUserProfile({
|
||||
...userProfile,
|
||||
notification_target: {
|
||||
target: chatID,
|
||||
type: Number(notificationTarget),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
alert('Notification target updated')
|
||||
})
|
||||
}
|
||||
|
@ -323,7 +347,7 @@ const NotificationSetting = () => {
|
|||
<Typography level='h3'>Custom Notification</Typography>
|
||||
<Divider />
|
||||
<Typography level='body-md'>
|
||||
Notificaiton through other platform like Telegram or Pushover
|
||||
Notification through other platform like Telegram or Pushover
|
||||
</Typography>
|
||||
|
||||
<FormControl orientation='horizontal'>
|
||||
|
@ -380,6 +404,7 @@ const NotificationSetting = () => {
|
|||
<Option value='0'>None</Option>
|
||||
<Option value='1'>Telegram</Option>
|
||||
<Option value='2'>Pushover</Option>
|
||||
<Option value='4'>Discord</Option>
|
||||
<Option value='3'>Webhooks</Option>
|
||||
</Select>
|
||||
{notificationTarget === '1' && (
|
||||
|
@ -438,6 +463,19 @@ const NotificationSetting = () => {
|
|||
/>
|
||||
</>
|
||||
)}
|
||||
{notificationTarget === '4' && (
|
||||
<>
|
||||
<Typography level='body-sm'>Webhook URL</Typography>
|
||||
<Input
|
||||
value={webhookURL}
|
||||
onChange={e => setWebhookURL(e.target.value)}
|
||||
placeholder='Webhook URL'
|
||||
sx={{
|
||||
width: '200px',
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{error && (
|
||||
<Typography color='warning' level='body-sm'>
|
||||
{error}
|
||||
|
|
|
@ -430,14 +430,18 @@ const TaskInput = ({ autoFocus, onChoreUpdate }) => {
|
|||
assignedTo: userProfile.id,
|
||||
assignStrategy: 'random',
|
||||
isRolling: false,
|
||||
notification: false,
|
||||
notification: true,
|
||||
description: description || null,
|
||||
labelsV2: [],
|
||||
priority: priority || 0,
|
||||
status: 0,
|
||||
frequencyType: 'once',
|
||||
frequencyMetadata: {},
|
||||
notificationMetadata: {},
|
||||
notificationMetadata: {
|
||||
dueDate: true,
|
||||
predue: true,
|
||||
nagging: true
|
||||
},
|
||||
}
|
||||
|
||||
if (frequency) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue