-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes + frontend UI to manage groups
- Loading branch information
Showing
18 changed files
with
476 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
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
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
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,36 @@ | ||
import { useQueryClient } from "@tanstack/react-query" | ||
import { YesOrNoModal } from "./YesOrNoModal" | ||
import { Title } from "@mantine/core" | ||
import { deleteGroup } from "@/utils/queries" | ||
import { notifications } from "@mantine/notifications" | ||
import { AttackGroup } from "@/utils/types" | ||
|
||
|
||
export const DeleteGroupModal = ({ onClose, group }:{ onClose: () => void, group?: AttackGroup }) => { | ||
const queryClient = useQueryClient() | ||
|
||
return <YesOrNoModal | ||
open={ group != null } | ||
onClose={onClose} | ||
title={<Title order={3}>Deleting an attack group</Title>} | ||
onConfirm={()=>{ | ||
if (group == null){ | ||
onClose?.() | ||
return | ||
} | ||
deleteGroup(group?.id).then(()=>{ | ||
notifications.show({ title: "Group deleted", message: `The group ${group?.name} has been deleted successfully`, color: "green" }) | ||
queryClient.invalidateQueries({ queryKey: ["groups"] }) | ||
|
||
}).catch((err)=>{ | ||
notifications.show({ title: "Error deleting the group", message: `An error occurred while deleting the group ${group?.name}: ${err.message}`, color: "red" }) | ||
}).finally(()=>{ onClose() }) | ||
}} | ||
size="xl" | ||
message={ | ||
<> | ||
<span>Are you sure you want to delete the group <b>{group?.name}</b>?</span><br /> | ||
<span style={{ color: "yellow" }}>This action will stop the group if it is running!</span> | ||
</> | ||
}/> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { editGroup } from "@/utils/queries" | ||
import { AttackGroup } from "@/utils/types" | ||
import { Button, Group, Modal, TextInput } from "@mantine/core" | ||
import { useForm } from "@mantine/form" | ||
import { notifications } from "@mantine/notifications" | ||
import { useQueryClient } from "@tanstack/react-query" | ||
import { useEffect } from "react" | ||
|
||
|
||
export const EditGroupModal = ({ onClose, group }:{ onClose: ()=>void, group?:AttackGroup }) => { | ||
const form = useForm({ | ||
initialValues: { | ||
name: group?.name??"", | ||
}, | ||
validate: { | ||
name: (value) => value == ""?"Name is required":undefined | ||
} | ||
}) | ||
|
||
const queryClient = useQueryClient() | ||
|
||
useEffect(() => { | ||
form.setInitialValues({ | ||
name: group?.name??"" | ||
}) | ||
form.reset() | ||
}, [group]) | ||
|
||
return <Modal | ||
opened={ group != null } | ||
onClose={onClose} | ||
title="Edit group" | ||
size="xl" | ||
centered | ||
> | ||
<form onSubmit={form.onSubmit((data) => { | ||
if (group == null){ | ||
onClose() | ||
return | ||
} | ||
editGroup(group.id, data) | ||
.then(()=>{ | ||
notifications.show({ | ||
title: `${group.name} Group edited!`, | ||
message: "Group has been edited successfully!", | ||
color: "green", | ||
}) | ||
queryClient.invalidateQueries({ queryKey: ["groups"] }) | ||
}).catch((err) => { | ||
notifications.show({ | ||
title: "Error during editing!", | ||
message: err.message??err??"Unknown error", | ||
color: "red", | ||
}) | ||
}).finally(()=>{ onClose() }) | ||
})}> | ||
<TextInput | ||
label="Name" | ||
placeholder="Group name" | ||
withAsterisk | ||
{...form.getInputProps("name")} | ||
/> | ||
<Group mt="xl" justify="flex-end"> | ||
<Button onClick={form.reset} color="gray" disabled={!form.isDirty()}>Reset</Button> | ||
<Button type="submit" color="blue" disabled={!form.isValid() || !form.isDirty()}>Edit</Button> | ||
</Group> | ||
</form> | ||
|
||
</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
Oops, something went wrong.