Skip to content

Commit

Permalink
feat: Empêche la soumission de nombre de collab négatif
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlaa committed Aug 1, 2024
1 parent 3c95191 commit 9913773
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,34 @@ import Trans from '@/components/translation/Trans'
import { ORGANISATION_TYPES } from '@/constants/organisations/organisationTypes'
import Select from '@/design-system/inputs/Select'
import TextInputGroup from '@/design-system/inputs/TextInputGroup'
import { useClientTranslation } from '@/hooks/useClientTranslation'
import { Organisation } from '@/types/organisations'
import { FieldValues, UseFormRegister } from 'react-hook-form'
import { FieldErrors, UseFormRegister } from 'react-hook-form'

type Values = {
name: string
administratorName: string
hasOptedInForCommunications: boolean
organisationType: string
email: string
position: string
numberOfCollaborators: number
administratorTelephone: string
}

type Props = {
organisation: Organisation | undefined
register: UseFormRegister<FieldValues>
register: UseFormRegister<Values>
errors: FieldErrors
}

export default function OrganisationFields({ organisation, register }: Props) {
export default function OrganisationFields({
organisation,
register,
errors,
}: Props) {
const { t } = useClientTranslation()

if (!organisation) return null

return (
Expand Down Expand Up @@ -52,7 +71,13 @@ export default function OrganisationFields({ organisation, register }: Props) {
</p>
}
value={organisation?.numberOfCollaborators}
{...register('numberOfCollaborators')}
{...register('numberOfCollaborators', {
min: {
value: 0,
message: t('Veuillez entrer un nombre positif.'),
},
})}
error={(errors.numberOfCollaborators?.message as string) || ''}
/>
<TextInputGroup
label={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export default function ParametresPage() {
email: user?.organisation?.administratorEmail ?? '',
})

const { register, handleSubmit } = useReactHookForm({
const {
register,
handleSubmit,
formState: { errors },
} = useReactHookForm({
defaultValues: {
name: organisation?.name ?? '',
administratorName: organisation?.administrators?.[0]?.name ?? '',
Expand Down Expand Up @@ -197,7 +201,8 @@ export default function ParametresPage() {

<OrganisationFields
organisation={organisation}
register={register as any}
register={register}
errors={errors}
/>

<Separator className="my-6" />
Expand Down

0 comments on commit 9913773

Please sign in to comment.