-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(landing): contact form #1636
base: master
Are you sure you want to change the base?
Conversation
purusott
commented
Sep 5, 2024
•
edited
Loading
edited
tavla/app/components/ContactForm.tsx
Outdated
} else { | ||
formRef.current?.reset() | ||
setIsOpen(false) | ||
addToast('Takk for din tilbakemelding!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Burde denne heller bli kalt når submit trykkes på?
const submit = async (data: FormData) => {
action(data)
setIsOpen(false)
addToast('Tavle slettet!')
}
tavla/app/components/ContactForm.tsx
Outdated
import { Expandable } from './Expandable' | ||
|
||
export function ContactForm() { | ||
const formRef = useRef<HTMLFormElement>(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeg antar vi setter en ref
fordi vi vil klare å nullstille formen, men i følge react kan vi heller gjøre det via en key
: https://react.dev/learn/preserving-and-resetting-state#resetting-a-form-with-a-key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fjernet ref, prøvde med key men fant ikke noen lur måte å oppdatere verdien på fra parent. Skal funke nå med usestate pga formerror, men lmk om det er en bedre måte 👍
265f6d6
to
4660f7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hadde bare en liten kommentar på bredde men hvis det er sjekka med Hannah og hun sier det er good så er det null stress.
bra jobba 👏👏👏
} | ||
case 'form/reset': { | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synes det virker litt rart å legge til en error-handling for å resette en form. Vi burde finne en annen løsning. Jeg tittet litt rundt, kanskje vi kan legge til et ekstra felt som heter "success"? Litt som de gjør her: https://react.dev/reference/react/useActionState#display-information-after-submitting-a-form
Vi kan sette oss ned å gjøre denne sammen tenker jeg:)
if (isEmptyOrSpaces(message)) | ||
return setFormError( | ||
getFormFeedbackForError('contact/message-missing'), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kan man flytte all denne valideringen til server-siden?
const validEmail = new RegExp(/^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/g)
if (!validEmail.test(email))
return getFormFeedbackForError('auth/missing-email')
if (isEmptyOrSpaces(message))
return getFormFeedbackForError('contact/message-missing')
Da tror jeg kanskje vi kan eliminere setFormError helt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det skjer i server også, så kan i prinsippet fjerne det helt. Tenkte bare det blir dårlig UX å validere bare i server (selv om det er viktigere der) mtp nettverkskall og latency.
Et alternativ er å bruke html sin innebygde validering. Da blir feilmeldingene på engelsk med mindre vi overstyrer med userefs
Men hvis vi kun ønsker server validering kan jeg fjerne usestate greiene :)