Skip to content

Commit

Permalink
fix: update perms
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Nov 14, 2024
1 parent 44204cd commit acb4a67
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 60 deletions.
20 changes: 10 additions & 10 deletions apps/client/@/shadcn/lib/types/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ export const PERMISSIONS_CONFIG = [
// "kb::manage"
// ]
// },
{
category: "System Settings",
permissions: [
"settings::view",
"settings::manage",
"webhook::manage",
"integration::manage",
"email_template::manage",
],
},
// {
// category: "System Settings",
// permissions: [
// "settings::view",
// "settings::manage",
// "webhook::manage",
// "integration::manage",
// "email_template::manage",
// ],
// },
// {
// category: "Time Tracking",
// permissions: [
Expand Down
149 changes: 99 additions & 50 deletions apps/client/components/TicketDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default function Ticket() {
async function update() {
if (data && data.ticket && data.ticket.locked) return;

await fetch(`/api/v1/ticket/update`, {
const res = await fetch(`/api/v1/ticket/update`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Expand All @@ -167,38 +167,52 @@ export default function Ticket() {
detail: JSON.stringify(debouncedValue),
note,
title: debounceTitle,
priority: priority ? priority.value : undefined,
status: ticketStatus ? ticketStatus.value : undefined,
priority: priority?.value,
status: ticketStatus?.value,
}),
})
.then((res) => res.json())
.then(() => {
setEdit(false);
}).then((res) => res.json());

if (!res.success) {
toast({
variant: "destructive",
title: "Error",
description: res.message || "Failed to update ticket",
});
return;
}
setEdit(false);
}

async function updateStatus() {
if (data && data.ticket && data.ticket.locked) return;

await fetch(`/api/v1/ticket/status/update`, {
const res = await fetch(`/api/v1/ticket/status/update`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
status: !data.ticket.isComplete,
id,
}),
})
.then((res) => res.json())
.then(() => refetch());
}).then((res) => res.json());

if (!res.success) {
toast({
variant: "destructive",
title: "Error",
description: res.message || "Failed to update status",
});
return;
}
refetch();
}

async function hide(hidden) {
if (data && data.ticket && data.ticket.locked) return;

await fetch(`/api/v1/ticket/status/hide`, {
const res = await fetch(`/api/v1/ticket/status/hide`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Expand All @@ -208,13 +222,21 @@ export default function Ticket() {
hidden,
id,
}),
})
.then((res) => res.json())
.then(() => refetch());
}).then((res) => res.json());

if (!res.success) {
toast({
variant: "destructive",
title: "Error",
description: res.message || "Failed to update visibility",
});
return;
}
refetch();
}

async function lock(locked) {
await fetch(`/api/v1/ticket/status/lock`, {
const res = await fetch(`/api/v1/ticket/status/lock`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Expand All @@ -224,9 +246,17 @@ export default function Ticket() {
locked,
id,
}),
})
.then((res) => res.json())
.then(() => refetch());
}).then((res) => res.json());

if (!res.success) {
toast({
variant: "destructive",
title: "Error",
description: res.message || "Failed to update lock status",
});
return;
}
refetch();
}

async function deleteIssue(locked) {
Expand Down Expand Up @@ -256,7 +286,7 @@ export default function Ticket() {
async function addComment() {
if (data && data.ticket && data.ticket.locked) return;

await fetch(`/api/v1/ticket/comment`, {
const res = await fetch(`/api/v1/ticket/comment`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -267,9 +297,17 @@ export default function Ticket() {
id,
public: publicComment,
}),
})
.then((res) => res.json())
.then(() => refetch());
}).then((res) => res.json());

if (!res.success) {
toast({
variant: "destructive",
title: "Error",
description: res.message || "Failed to add comment",
});
return;
}
refetch();
}

async function deleteComment(id: string) {
Expand Down Expand Up @@ -326,44 +364,55 @@ export default function Ticket() {
}

async function fetchUsers() {
await fetch(`/api/v1/users/all`, {
const res = await fetch(`/api/v1/users/all`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
})
.then((res) => res.json())
.then((res) => {
if (res) {
setUsers(res.users);
}
}).then((res) => res.json());

if (!res.success) {
toast({
variant: "destructive",
title: "Error",
description: res.message || "Failed to fetch users",
});
return;
}

if (res.users) {
setUsers(res.users);
}
}

async function transferTicket() {
if (data && data.ticket && data.ticket.locked) return;
if (n === undefined) return;

if (n !== undefined) {
await fetch(`/api/v1/ticket/transfer`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
user: n.id,
id,
}),
})
.then((res) => res.json())
.then((res) => {
if (res.success) {
setAssignedEdit(false);
refetch();
}
});
const res = await fetch(`/api/v1/ticket/transfer`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
user: n.id,
id,
}),
}).then((res) => res.json());

if (!res.success) {
toast({
variant: "destructive",
title: "Error",
description: res.message || "Failed to transfer ticket",
});
return;
}

setAssignedEdit(false);
refetch();
}

const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down

0 comments on commit acb4a67

Please sign in to comment.