-
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
1 parent
cc35d78
commit 15dfa76
Showing
3 changed files
with
151 additions
and
3 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
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
79 changes: 79 additions & 0 deletions
79
frontend/src/pages/administration/mentor/users/view/_modals/UVDeleteEndorsement.modal.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,79 @@ | ||
import { Modal } from "@/components/ui/Modal/Modal"; | ||
import { UserModel, UserSoloModel } from "@/models/UserModel"; | ||
import { Input } from "@/components/ui/Input/Input"; | ||
import { getAtcRatingCombined } from "@/utils/helper/vatsim/AtcRatingHelper"; | ||
import { Separator } from "@/components/ui/Separator/Separator"; | ||
import { Select } from "@/components/ui/Select/Select"; | ||
import dayjs from "dayjs"; | ||
import React, { Dispatch, FormEvent, useState } from "react"; | ||
import { Button } from "@/components/ui/Button/Button"; | ||
import { TbPlaylistAdd, TbTrack, TbTrash } from "react-icons/tb"; | ||
import { COLOR_OPTS } from "@/assets/theme.config"; | ||
import FormHelper from "@/utils/helper/FormHelper"; | ||
import { axiosInstance } from "@/utils/network/AxiosInstance"; | ||
import ToastHelper from "@/utils/helper/ToastHelper"; | ||
import { AxiosResponse } from "axios"; | ||
import { EndorsementGroupModel } from "@/models/EndorsementGroupModel"; | ||
import useApi from "@/utils/hooks/useApi"; | ||
import { MapArray } from "@/components/conditionals/MapArray"; | ||
|
||
export function UVDeleteSoloModal({ show, onClose, user, setUser }: { show: boolean; onClose: () => any; user?: UserModel; setUser: Dispatch<UserModel> }) { | ||
const [deletingSolo, setDeletingSolo] = useState<boolean>(false); | ||
|
||
function deleteSolo(e: FormEvent<HTMLFormElement>) { | ||
e.preventDefault(); | ||
|
||
if (user == null || user.user_solo == null) { | ||
return; | ||
} | ||
setDeletingSolo(true); | ||
|
||
axiosInstance | ||
.delete("/administration/solo", { | ||
data: { | ||
solo_id: user.user_solo.id, | ||
trainee_id: user.id, | ||
}, | ||
}) | ||
.then(res => { | ||
const data: UserModel = res.data as UserModel; | ||
|
||
setUser({ | ||
...user, | ||
user_solo: undefined, | ||
endorsement_groups: data.endorsement_groups, | ||
}); | ||
ToastHelper.success("Freigabe erfolgreich gelöscht"); | ||
onClose(); | ||
}) | ||
.catch(() => { | ||
ToastHelper.error("Fehler beim Löschen der Freigabe"); | ||
}) | ||
.finally(() => setDeletingSolo(false)); | ||
} | ||
|
||
return ( | ||
<form onSubmit={deleteSolo}> | ||
<Modal | ||
show={show} | ||
onClose={onClose} | ||
title={"Freigabe Löschen"} | ||
footer={ | ||
<Button type={"submit"} loading={deletingSolo} icon={<TbTrash size={20} />} color={COLOR_OPTS.DANGER} variant={"twoTone"}> | ||
Löschen | ||
</Button> | ||
}> | ||
|
||
<Separator /> | ||
|
||
<p> | ||
Bist du sicher, dass du die Freigabe von{" "} | ||
<strong> | ||
{user?.first_name} {user?.last_name} | ||
</strong>{" "} | ||
löschen möchtest? Diese Aktion kann nicht rückgängig gemacht werden. | ||
</p> | ||
</Modal> | ||
</form> | ||
); | ||
} |