From 6f077f141edcc45f2d7467b7c796e62a8f0316f8 Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Thu, 7 Dec 2023 20:12:40 -0500 Subject: Prevent removing participants with expenses --- src/components/group-form.tsx | 57 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 11 deletions(-) (limited to 'src/components/group-form.tsx') diff --git a/src/components/group-form.tsx b/src/components/group-form.tsx index d2140f0..7bf0f8e 100644 --- a/src/components/group-form.tsx +++ b/src/components/group-form.tsx @@ -18,6 +18,11 @@ import { FormLabel, FormMessage, } from '@/components/ui/form' +import { + HoverCard, + HoverCardContent, + HoverCardTrigger, +} from '@/components/ui/hover-card' import { Input } from '@/components/ui/input' import { getGroup } from '@/lib/api' import { GroupFormValues, groupFormSchema } from '@/lib/schemas' @@ -28,9 +33,14 @@ import { useFieldArray, useForm } from 'react-hook-form' export type Props = { group?: NonNullable>> onSubmit: (groupFormValues: GroupFormValues) => Promise + protectedParticipantIds?: string[] } -export function GroupForm({ group, onSubmit }: Props) { +export function GroupForm({ + group, + onSubmit, + protectedParticipantIds = [], +}: Props) { const form = useForm({ resolver: zodResolver(groupFormSchema), defaultValues: group @@ -48,6 +58,7 @@ export function GroupForm({ group, onSubmit }: Props) { const { fields, append, remove } = useFieldArray({ control: form.control, name: 'participants', + keyName: 'key', }) return ( @@ -115,7 +126,7 @@ export function GroupForm({ group, onSubmit }: Props) { -
    +
      {fields.map((item, index) => (
    • - + {item.id && + protectedParticipantIds.includes(item.id) ? ( + + + + + + This participant is part of expenses, and can + not be removed. + + + ) : ( + + )}
      -- cgit v1.3