hid create and delete role buttons to prevent catastrophe
This commit is contained in:
@@ -10,7 +10,9 @@ export type Role = {
|
|||||||
const addr = import.meta.env.VITE_APIHOST;
|
const addr = import.meta.env.VITE_APIHOST;
|
||||||
|
|
||||||
export async function getRoles(): Promise<Role[]> {
|
export async function getRoles(): Promise<Role[]> {
|
||||||
const res = await fetch(`${addr}/roles`)
|
const res = await fetch(`${addr}/roles`, {
|
||||||
|
credentials: 'include',
|
||||||
|
})
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
return res.json() as Promise<Role[]>;
|
return res.json() as Promise<Role[]>;
|
||||||
@@ -26,11 +28,12 @@ export async function createRole(name: string, color: string, description: strin
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
|
credentials: 'include',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name,
|
name,
|
||||||
color,
|
color,
|
||||||
description
|
description
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -47,6 +50,7 @@ export async function addMemberToRole(member_id: number, role_id: number): Promi
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
|
credentials: 'include',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
member_id,
|
member_id,
|
||||||
role_id
|
role_id
|
||||||
@@ -83,7 +87,8 @@ export async function removeMemberFromRole(member_id: number, role_id: number):
|
|||||||
|
|
||||||
export async function deleteRole(role_id: number): Promise<boolean> {
|
export async function deleteRole(role_id: number): Promise<boolean> {
|
||||||
const res = await fetch(`${addr}/roles/${role_id}`, {
|
const res = await fetch(`${addr}/roles/${role_id}`, {
|
||||||
method: "DELETE"
|
method: "DELETE",
|
||||||
|
credentials: 'include',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ import { Plus, X } from 'lucide-vue-next';
|
|||||||
import Separator from '@/components/ui/separator/Separator.vue';
|
import Separator from '@/components/ui/separator/Separator.vue';
|
||||||
import Input from '@/components/ui/input/Input.vue';
|
import Input from '@/components/ui/input/Input.vue';
|
||||||
import Label from '@/components/ui/label/Label.vue';
|
import Label from '@/components/ui/label/Label.vue';
|
||||||
import { getMembers, Member } from '@/api/member';
|
import { getMembers } from '@/api/member';
|
||||||
|
import { Member } from '@shared/types/member';
|
||||||
|
|
||||||
const roles = ref<Role[]>([])
|
const roles = ref<Role[]>([])
|
||||||
const activeRole = ref<Role | null>(null)
|
const activeRole = ref<Role | null>(null)
|
||||||
@@ -116,16 +117,18 @@ async function handleCreateGroup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAddMember() {
|
async function handleAddMember() {
|
||||||
//guard
|
//guard
|
||||||
if (memberToAdd.value == null)
|
if (memberToAdd.value == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
addMemberToRole(memberToAdd.value.member_id, activeRole.value.id);
|
await addMemberToRole(memberToAdd.value.member_id, activeRole.value.id);
|
||||||
|
roles.value = await getRoles();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRemoveMember(memberId: number) {
|
async function handleRemoveMember(memberId: number) {
|
||||||
removeMemberFromRole(memberId, activeRole.value.id);
|
removeMemberFromRole(memberId, activeRole.value.id);
|
||||||
|
roles.value = await getRoles();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleDeleteRole() {
|
async function handleDeleteRole() {
|
||||||
@@ -193,7 +196,7 @@ onMounted(async () => {
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button @click="handleDeleteRole">Delete Group</Button>
|
<!-- <Button @click="handleDeleteRole">Delete Group</Button> -->
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
@@ -232,7 +235,7 @@ onMounted(async () => {
|
|||||||
<div class="max-w-5xl mx-auto">
|
<div class="max-w-5xl mx-auto">
|
||||||
<div class="flex items-center justify-between my-4">
|
<div class="flex items-center justify-between my-4">
|
||||||
<p>Groups</p>
|
<p>Groups</p>
|
||||||
<Button @click="showCreateGroupDialog = true">+ Add New Group</Button>
|
<!-- <Button @click="showCreateGroupDialog = true">+ Add New Group</Button> -->
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-3 gap-5">
|
<div class="grid grid-cols-3 gap-5">
|
||||||
<Card v-for="value in roles" :key="value.id" @click="activeRole = value; showDialog = true"
|
<Card v-for="value in roles" :key="value.id" @click="activeRole = value; showDialog = true"
|
||||||
|
|||||||
Reference in New Issue
Block a user