Skip to content

Commit

Permalink
feat: resend RSVP message on dupe submission
Browse files Browse the repository at this point in the history
  • Loading branch information
mplewis committed Nov 20, 2024
1 parent dec77fc commit 444fec5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
- [ ] Why are hamburger items missing on Confirm RSVP page?
- [ ] URL builder helpers
- [ ] Form to request resend link(s) for email address
- [ ] Resend confirmation if an RSVP enters an existing email
- [ ] Add Sentry to frontend
- [ ] Diff dates in `notify` so that they are omitted when unchanged
- [ ] Investigate why some emailed URLs use incorrect hosts for Netlify Deploy Preview
Expand All @@ -41,6 +40,8 @@
- [ ] Consensually gather user emails for mailing list
- [ ] Add pretty error messages for 404s (e.g. clicked an expired/tidied link)
- [ ] Redirect old slugs on slug change
- [ ] Add sticky bit to "sent you a confirmation email for your RSVP"
- [x] Resend confirmation if an RSVP enters an existing email
- [x] Hold RSVP locally with cookie
- [x] **Scheduler engine**
- [x] Send reminders
Expand Down
14 changes: 14 additions & 0 deletions api/src/services/responses/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type {
Reminder,
} from 'types/graphql'

import { RedwoodError } from '@redwoodjs/api'

import { db } from 'src/lib/db'
import {
sendNewResponseReceived,
Expand Down Expand Up @@ -96,6 +98,18 @@ export const createResponse: MutationResolvers['createResponse'] = async ({
const event = await db.event.findUnique({ where: { id: eventId } })
if (!event) throw new Error(`Event not found: ${eventId}`)

const existingResponse = await db.response.findFirst({
where: { eventId, email: input.email },
})
if (existingResponse) {
await sendResponseConfirmation({ event, response: existingResponse })
throw new RedwoodError(
`You have already RSVPed to this event. ` +
`We've resent your confirmation email to ${input.email}.`,
{ forbidResubmitForEmail: input.email }
)
}

const reminders: { sendAt: Date }[] = []
if (input.remindPriorSec) {
const sendAt = dayjs(event.start)
Expand Down
13 changes: 11 additions & 2 deletions web/src/components/ResponseForm/ResponseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ function random<T>(choices: T[]): T {

const ResponseForm = (props: Props) => {
const { mode, event, error, loading, formMethods, onChange, onSubmit } = props
const { formState } = formMethods
const { formState, getValues } = formMethods

const { email } = getValues()
const forbidResubmit =
email === error?.cause?.extensions?.['forbidResubmitForEmail']

const [exampleName, setExampleName] = useState('')
useEffect(() => {
Expand Down Expand Up @@ -153,7 +157,12 @@ const ResponseForm = (props: Props) => {

<Submit
className="button is-success mt-3"
disabled={loading || !formState.isValid || !formState.isDirty}
disabled={
loading ||
!formState.isValid ||
!formState.isDirty ||
forbidResubmit
}
>
{mode === 'CREATE'
? loading
Expand Down

0 comments on commit 444fec5

Please sign in to comment.