({ item, settings }: ProjectCardProps)
| 46 | } |
| 47 | |
| 48 | function ProjectCard({ item, settings }: ProjectCardProps) { |
| 49 | const queryClient = useQueryClient() |
| 50 | |
| 51 | const [deleteProjectDialogOpen, setDeleteProjectDialogOpen] = |
| 52 | React.useState(false) |
| 53 | |
| 54 | const [projectOperation, setProjectOperation] = React.useState< |
| 55 | 'launch' | 'stop' | 'delete' |
| 56 | >() |
| 57 | const [projectStatusDialogOpen, setProjectStatusDialogOpen] = |
| 58 | React.useState(false) |
| 59 | |
| 60 | const launchProjectMutation = useMutation({ |
| 61 | mutationFn: async () => { |
| 62 | const response = await fetch(`/api/projects/${item.id}/start`, { |
| 63 | method: 'POST', |
| 64 | headers: { |
| 65 | 'Content-Type': 'application/json', |
| 66 | }, |
| 67 | }) |
| 68 | const data = await response.json() |
| 69 | return data |
| 70 | }, |
| 71 | onSettled: () => { |
| 72 | queryClient.invalidateQueries({ queryKey: ['projects'] }) |
| 73 | }, |
| 74 | }) |
| 75 | |
| 76 | const stopProjectMutation = useMutation({ |
| 77 | mutationFn: async () => { |
| 78 | const response = await fetch(`/api/projects/${item.id}/stop`, { |
| 79 | method: 'POST', |
| 80 | headers: { |
| 81 | 'Content-Type': 'application/json', |
| 82 | }, |
| 83 | }) |
| 84 | const data = await response.json() |
| 85 | return data |
| 86 | }, |
| 87 | onSettled: () => { |
| 88 | queryClient.invalidateQueries({ queryKey: ['projects'] }) |
| 89 | }, |
| 90 | }) |
| 91 | |
| 92 | const deleteProjectMutation = useMutation({ |
| 93 | mutationFn: async () => { |
| 94 | const response = await fetch(`/api/projects/${item.id}/delete`, { |
| 95 | method: 'POST', |
| 96 | headers: { |
| 97 | 'Content-Type': 'application/json', |
| 98 | }, |
| 99 | }) |
| 100 | const data = await response.json() |
| 101 | return data |
| 102 | }, |
| 103 | onSettled: () => { |
| 104 | queryClient.invalidateQueries({ queryKey: ['projects'] }) |
| 105 | }, |
nothing calls this directly
no test coverage detected