({
value,
onChange,
projectId,
}: {
value: string;
onChange: (value: string) => void;
projectId: string;
})
| 149 | } |
| 150 | |
| 151 | function SelectDashboard({ |
| 152 | value, |
| 153 | onChange, |
| 154 | projectId, |
| 155 | }: { |
| 156 | value: string; |
| 157 | onChange: (value: string) => void; |
| 158 | projectId: string; |
| 159 | }) { |
| 160 | const trpc = useTRPC(); |
| 161 | const queryClient = useQueryClient(); |
| 162 | const [isCreatingNew, setIsCreatingNew] = useState(false); |
| 163 | const [newDashboardName, setNewDashboardName] = useState(''); |
| 164 | |
| 165 | const form = useForm({ |
| 166 | resolver: zodResolver(z.object({ name: z.string().min(1, 'Required') })), |
| 167 | defaultValues: { |
| 168 | name: '', |
| 169 | }, |
| 170 | }); |
| 171 | |
| 172 | const dashboardQuery = useQuery( |
| 173 | trpc.dashboard.list.queryOptions({ |
| 174 | projectId: projectId!, |
| 175 | }), |
| 176 | ); |
| 177 | |
| 178 | const dashboardMutation = useMutation( |
| 179 | trpc.dashboard.create.mutationOptions({ |
| 180 | onError: handleError, |
| 181 | async onSuccess(res) { |
| 182 | queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); |
| 183 | await dashboardQuery.refetch(); |
| 184 | onChange(res.id); |
| 185 | setIsCreatingNew(false); |
| 186 | setNewDashboardName(''); |
| 187 | form.reset(); |
| 188 | }, |
| 189 | }), |
| 190 | ); |
| 191 | |
| 192 | const handleSelectChange = (selectedValue: string) => { |
| 193 | if (selectedValue === 'create-new') { |
| 194 | setIsCreatingNew(true); |
| 195 | onChange(''); // Clear the current selection |
| 196 | } else { |
| 197 | setIsCreatingNew(false); |
| 198 | onChange(selectedValue); |
| 199 | } |
| 200 | }; |
| 201 | |
| 202 | const handleCreateDashboard = () => { |
| 203 | if (newDashboardName.trim()) { |
| 204 | dashboardMutation.mutate({ |
| 205 | name: newDashboardName.trim(), |
| 206 | projectId, |
| 207 | }); |
| 208 | } |
nothing calls this directly
no test coverage detected