diff --git a/src/utils/Fetcher.jsx b/src/utils/Fetcher.jsx index bc18823..9449cf5 100644 --- a/src/utils/Fetcher.jsx +++ b/src/utils/Fetcher.jsx @@ -462,6 +462,15 @@ const GetChoresHistory = async (limit, includeMembers) => { }) return resp.json() } + +const PutWebhookURL = url => { + return Fetch(`/users/webhook`, { + method: 'PUT', + headers: HEADERS(), + body: JSON.stringify({ url }), + }) +} + export { AcceptCircleMemberRequest, ArchiveChore, @@ -499,6 +508,7 @@ export { LeaveCircle, MarkChoreComplete, PutNotificationTarget, + PutWebhookURL, RedeemPoints, RefreshToken, ResetPassword, diff --git a/src/views/Settings/Settings.jsx b/src/views/Settings/Settings.jsx index bd445d5..8ec486c 100644 --- a/src/views/Settings/Settings.jsx +++ b/src/views/Settings/Settings.jsx @@ -2,6 +2,7 @@ import { Box, Button, Card, + Checkbox, Chip, CircularProgress, Container, @@ -24,6 +25,7 @@ import { GetUserProfile, JoinCircle, LeaveCircle, + PutWebhookURL, UpdatePassword, } from '../../utils/Fetcher' import PassowrdChangeModal from '../Modals/Inputs/PasswordChangeModal' @@ -37,6 +39,9 @@ const Settings = () => { const [circleMemberRequests, setCircleMemberRequests] = useState([]) const [circleInviteCode, setCircleInviteCode] = useState('') const [circleMembers, setCircleMembers] = useState([]) + const [webhookURL, setWebhookURL] = useState(null) + const [webhookError, setWebhookError] = useState(null) + const [changePasswordModal, setChangePasswordModal] = useState(false) useEffect(() => { GetUserProfile().then(resp => { @@ -47,6 +52,7 @@ const Settings = () => { GetUserCircle().then(resp => { resp.json().then(data => { setUserCircles(data.res ? data.res : []) + setWebhookURL(data.res ? data.res[0].webhook_url : null) }) }) GetCircleMemberRequests().then(resp => { @@ -116,7 +122,7 @@ const Settings = () => { return (
- Sharing settings + Circle settings Your account is automatically connected to a Circle when you create or @@ -184,6 +190,7 @@ const Settings = () => { )} + Circle Members {circleMembers.map(member => ( @@ -309,6 +316,65 @@ const Settings = () => { Join Circle + {circleMembers.find(m => userProfile.id == m.userId).role === + 'admin' && ( + <> + + Webhook + + + Webhooks allow you to send real-time notifications to other + services when events happen in your Circle. Use the webhook URL + below to + + { + if (webhookURL === null) { + setWebhookURL('') + } else { + setWebhookURL(null) + } + }} + variant='soft' + label={'Enable Webhook'} + /> + <> + {webhookURL !== null && ( + + Webhook URL + setWebhookURL(e.target.value)} + size='lg' + sx={{ + width: '220px', + mb: 1, + }} + /> + + {webhookError} + + + )} + + + + )}