({ id }: Props)
| 26 | } |
| 27 | |
| 28 | export default function EditEvent({ id }: Props) { |
| 29 | const { projectId } = useAppParams(); |
| 30 | const trpc = useTRPC(); |
| 31 | const client = useQueryClient(); |
| 32 | |
| 33 | const { data: event } = useQuery( |
| 34 | trpc.event.byId.queryOptions({ id, projectId }), |
| 35 | ); |
| 36 | |
| 37 | const [selectedIcon, setIcon] = useState<string | null>(null); |
| 38 | const [selectedColor, setColor] = useState(EventIconRecords.default!.color); |
| 39 | const [conversion, setConversion] = useState(false); |
| 40 | const [step, setStep] = useState<'icon' | 'color'>('icon'); |
| 41 | useEffect(() => { |
| 42 | if (event?.meta?.icon) { |
| 43 | setIcon(event.meta.icon); |
| 44 | } |
| 45 | if (event?.meta?.color) { |
| 46 | setColor(event.meta.color); |
| 47 | } |
| 48 | if (event?.meta?.conversion) { |
| 49 | setConversion(event.meta.conversion); |
| 50 | } |
| 51 | }, [event]); |
| 52 | |
| 53 | const SelectedIcon = selectedIcon ? EventIconMapper[selectedIcon] : null; |
| 54 | |
| 55 | const mutation = useMutation( |
| 56 | trpc.event.updateEventMeta.mutationOptions({ |
| 57 | onSuccess() { |
| 58 | toast('Event updated'); |
| 59 | client.invalidateQueries(trpc.event.pathFilter()); |
| 60 | popModal(); |
| 61 | }, |
| 62 | }), |
| 63 | ); |
| 64 | const getBg = (color: string) => `bg-${color}-200`; |
| 65 | const getText = (color: string) => `text-${color}-700`; |
| 66 | const iconGrid = 'grid grid-cols-10 gap-4'; |
| 67 | const [search, setSearch] = useState(''); |
| 68 | return ( |
| 69 | <ModalContent> |
| 70 | <ModalHeader |
| 71 | title={`Edit: ${event?.name}`} |
| 72 | text={`Changes here will affect all "${event?.name}" events`} |
| 73 | /> |
| 74 | <div className="col gap-4"> |
| 75 | <div> |
| 76 | <Label className="mb-4 block">Conversion</Label> |
| 77 | <label className="flex cursor-pointer select-none items-center gap-4 rounded-md border border-border p-4"> |
| 78 | <Checkbox |
| 79 | checked={conversion} |
| 80 | onCheckedChange={(checked) => { |
| 81 | if (checked === 'indeterminate') return; |
| 82 | setConversion(checked); |
| 83 | }} |
| 84 | /> |
| 85 | <div> |
nothing calls this directly
no test coverage detected