Add PutWebhookURL function to update user webhook URL

This commit is contained in:
Mo Tarbin 2025-02-11 20:46:58 -05:00
parent d0b1addc6f
commit bf9ffc97f2
2 changed files with 77 additions and 1 deletions

View file

@ -462,6 +462,15 @@ const GetChoresHistory = async (limit, includeMembers) => {
}) })
return resp.json() return resp.json()
} }
const PutWebhookURL = url => {
return Fetch(`/users/webhook`, {
method: 'PUT',
headers: HEADERS(),
body: JSON.stringify({ url }),
})
}
export { export {
AcceptCircleMemberRequest, AcceptCircleMemberRequest,
ArchiveChore, ArchiveChore,
@ -499,6 +508,7 @@ export {
LeaveCircle, LeaveCircle,
MarkChoreComplete, MarkChoreComplete,
PutNotificationTarget, PutNotificationTarget,
PutWebhookURL,
RedeemPoints, RedeemPoints,
RefreshToken, RefreshToken,
ResetPassword, ResetPassword,

View file

@ -2,6 +2,7 @@ import {
Box, Box,
Button, Button,
Card, Card,
Checkbox,
Chip, Chip,
CircularProgress, CircularProgress,
Container, Container,
@ -24,6 +25,7 @@ import {
GetUserProfile, GetUserProfile,
JoinCircle, JoinCircle,
LeaveCircle, LeaveCircle,
PutWebhookURL,
UpdatePassword, UpdatePassword,
} from '../../utils/Fetcher' } from '../../utils/Fetcher'
import PassowrdChangeModal from '../Modals/Inputs/PasswordChangeModal' import PassowrdChangeModal from '../Modals/Inputs/PasswordChangeModal'
@ -37,6 +39,9 @@ const Settings = () => {
const [circleMemberRequests, setCircleMemberRequests] = useState([]) const [circleMemberRequests, setCircleMemberRequests] = useState([])
const [circleInviteCode, setCircleInviteCode] = useState('') const [circleInviteCode, setCircleInviteCode] = useState('')
const [circleMembers, setCircleMembers] = useState([]) const [circleMembers, setCircleMembers] = useState([])
const [webhookURL, setWebhookURL] = useState(null)
const [webhookError, setWebhookError] = useState(null)
const [changePasswordModal, setChangePasswordModal] = useState(false) const [changePasswordModal, setChangePasswordModal] = useState(false)
useEffect(() => { useEffect(() => {
GetUserProfile().then(resp => { GetUserProfile().then(resp => {
@ -47,6 +52,7 @@ const Settings = () => {
GetUserCircle().then(resp => { GetUserCircle().then(resp => {
resp.json().then(data => { resp.json().then(data => {
setUserCircles(data.res ? data.res : []) setUserCircles(data.res ? data.res : [])
setWebhookURL(data.res ? data.res[0].webhook_url : null)
}) })
}) })
GetCircleMemberRequests().then(resp => { GetCircleMemberRequests().then(resp => {
@ -116,7 +122,7 @@ const Settings = () => {
return ( return (
<Container> <Container>
<div className='grid gap-4 py-4' id='sharing'> <div className='grid gap-4 py-4' id='sharing'>
<Typography level='h3'>Sharing settings</Typography> <Typography level='h3'>Circle settings</Typography>
<Divider /> <Divider />
<Typography level='body-md'> <Typography level='body-md'>
Your account is automatically connected to a Circle when you create or Your account is automatically connected to a Circle when you create or
@ -184,6 +190,7 @@ const Settings = () => {
</Button> </Button>
)} )}
</Typography> </Typography>
<Typography level='title-md'>Circle Members</Typography> <Typography level='title-md'>Circle Members</Typography>
{circleMembers.map(member => ( {circleMembers.map(member => (
<Card key={member.id} className='p-4'> <Card key={member.id} className='p-4'>
@ -309,6 +316,65 @@ const Settings = () => {
Join Circle Join Circle
</Button> </Button>
</Typography> </Typography>
{circleMembers.find(m => userProfile.id == m.userId).role ===
'admin' && (
<>
<Typography level='title-lg' mt={2}>
Webhook
</Typography>
<Typography level='body-md' mt={-1}>
Webhooks allow you to send real-time notifications to other
services when events happen in your Circle. Use the webhook URL
below to
</Typography>
<Checkbox
checked={webhookURL !== null}
onClick={() => {
if (webhookURL === null) {
setWebhookURL('')
} else {
setWebhookURL(null)
}
}}
variant='soft'
label={'Enable Webhook'}
/>
<>
{webhookURL !== null && (
<Typography level='title-sm'>
Webhook URL
<Input
value={webhookURL ? webhookURL : ''}
onChange={e => setWebhookURL(e.target.value)}
size='lg'
sx={{
width: '220px',
mb: 1,
}}
/>
<Typography level='body-sm' color='danger'>
{webhookError}
</Typography>
</Typography>
)}
<Button
variant='soft'
sx={{ width: '110px' }}
onClick={() => {
PutWebhookURL(webhookURL).then(resp => {
if (resp.ok) {
alert('Webhook URL updated successfully.')
} else {
alert('Failed to update webhook URL.')
}
})
}}
>
Save
</Button>
</>
</>
)}
</div> </div>
<div className='grid gap-4 py-4' id='account'> <div className='grid gap-4 py-4' id='account'>