-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Net.Vatprc.Uniapi.UI.Event/src/components/delete-airspace.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { invalidatePath, useApi, useApiDelete } from "@/client"; | ||
import { useUser } from "@/services/auth"; | ||
import { ActionIcon, Button, Group, Modal, Stack, Text } from "@mantine/core"; | ||
import { useDisclosure } from "@mantine/hooks"; | ||
import { useRouter } from "@tanstack/react-router"; | ||
import { IoTrash } from "react-icons/io5"; | ||
|
||
export const DeleteAirspace = ({ eventId, airspaceId }: { eventId: string; airspaceId: string }) => { | ||
const user = useUser(); | ||
const { data: airspace, isLoading } = useApi(`/api/events/{eid}/airspaces/{aid}`, { | ||
path: { eid: eventId, aid: airspaceId }, | ||
enabled: !!eventId, | ||
}); | ||
const { navigate } = useRouter(); | ||
const { mutate, isPending } = useApiDelete( | ||
"/api/events/{eid}/airspaces/{aid}", | ||
{ path: { eid: eventId, aid: airspaceId } }, | ||
async () => { | ||
await invalidatePath("/api/events/{eid}/airspaces", { eid: eventId }); | ||
close(); | ||
await navigate({ to: "/events/" + eventId }); | ||
}, | ||
); | ||
const [opened, { toggle, close }] = useDisclosure(false); | ||
|
||
if (!user?.roles.includes("ec")) return null; | ||
|
||
return ( | ||
<> | ||
<ActionIcon variant="subtle" color="red" aria-label="Settings" onClick={toggle}> | ||
<IoTrash /> | ||
</ActionIcon> | ||
<Modal opened={opened} onClose={close} title="Delete Event"> | ||
<Stack> | ||
<Text>Do you want to delete airspace {airspace?.name}?</Text> | ||
<Group> | ||
<Button onClick={toggle}>Cancel</Button> | ||
<Button color="red" onClick={() => mutate({})} loading={isPending} disabled={isLoading}> | ||
Yes | ||
</Button> | ||
</Group> | ||
</Stack> | ||
</Modal> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters