Skip to content

Commit acb4a67

Browse files
committed
fix: update perms
1 parent 44204cd commit acb4a67

File tree

2 files changed

+109
-60
lines changed

2 files changed

+109
-60
lines changed

apps/client/@/shadcn/lib/types/permissions.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,16 @@ export const PERMISSIONS_CONFIG = [
168168
// "kb::manage"
169169
// ]
170170
// },
171-
{
172-
category: "System Settings",
173-
permissions: [
174-
"settings::view",
175-
"settings::manage",
176-
"webhook::manage",
177-
"integration::manage",
178-
"email_template::manage",
179-
],
180-
},
171+
// {
172+
// category: "System Settings",
173+
// permissions: [
174+
// "settings::view",
175+
// "settings::manage",
176+
// "webhook::manage",
177+
// "integration::manage",
178+
// "email_template::manage",
179+
// ],
180+
// },
181181
// {
182182
// category: "Time Tracking",
183183
// permissions: [

apps/client/components/TicketDetails/index.tsx

Lines changed: 99 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default function Ticket() {
156156
async function update() {
157157
if (data && data.ticket && data.ticket.locked) return;
158158

159-
await fetch(`/api/v1/ticket/update`, {
159+
const res = await fetch(`/api/v1/ticket/update`, {
160160
method: "PUT",
161161
headers: {
162162
"Content-Type": "application/json",
@@ -167,38 +167,52 @@ export default function Ticket() {
167167
detail: JSON.stringify(debouncedValue),
168168
note,
169169
title: debounceTitle,
170-
priority: priority ? priority.value : undefined,
171-
status: ticketStatus ? ticketStatus.value : undefined,
170+
priority: priority?.value,
171+
status: ticketStatus?.value,
172172
}),
173-
})
174-
.then((res) => res.json())
175-
.then(() => {
176-
setEdit(false);
173+
}).then((res) => res.json());
174+
175+
if (!res.success) {
176+
toast({
177+
variant: "destructive",
178+
title: "Error",
179+
description: res.message || "Failed to update ticket",
177180
});
181+
return;
182+
}
183+
setEdit(false);
178184
}
179185

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

183-
await fetch(`/api/v1/ticket/status/update`, {
189+
const res = await fetch(`/api/v1/ticket/status/update`, {
184190
method: "PUT",
185191
headers: {
186-
"Content-Type": "application/json",
192+
"Content-Type": "application/json",
187193
Authorization: `Bearer ${token}`,
188194
},
189195
body: JSON.stringify({
190196
status: !data.ticket.isComplete,
191197
id,
192198
}),
193-
})
194-
.then((res) => res.json())
195-
.then(() => refetch());
199+
}).then((res) => res.json());
200+
201+
if (!res.success) {
202+
toast({
203+
variant: "destructive",
204+
title: "Error",
205+
description: res.message || "Failed to update status",
206+
});
207+
return;
208+
}
209+
refetch();
196210
}
197211

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

201-
await fetch(`/api/v1/ticket/status/hide`, {
215+
const res = await fetch(`/api/v1/ticket/status/hide`, {
202216
method: "PUT",
203217
headers: {
204218
"Content-Type": "application/json",
@@ -208,13 +222,21 @@ export default function Ticket() {
208222
hidden,
209223
id,
210224
}),
211-
})
212-
.then((res) => res.json())
213-
.then(() => refetch());
225+
}).then((res) => res.json());
226+
227+
if (!res.success) {
228+
toast({
229+
variant: "destructive",
230+
title: "Error",
231+
description: res.message || "Failed to update visibility",
232+
});
233+
return;
234+
}
235+
refetch();
214236
}
215237

216238
async function lock(locked) {
217-
await fetch(`/api/v1/ticket/status/lock`, {
239+
const res = await fetch(`/api/v1/ticket/status/lock`, {
218240
method: "PUT",
219241
headers: {
220242
"Content-Type": "application/json",
@@ -224,9 +246,17 @@ export default function Ticket() {
224246
locked,
225247
id,
226248
}),
227-
})
228-
.then((res) => res.json())
229-
.then(() => refetch());
249+
}).then((res) => res.json());
250+
251+
if (!res.success) {
252+
toast({
253+
variant: "destructive",
254+
title: "Error",
255+
description: res.message || "Failed to update lock status",
256+
});
257+
return;
258+
}
259+
refetch();
230260
}
231261

232262
async function deleteIssue(locked) {
@@ -256,7 +286,7 @@ export default function Ticket() {
256286
async function addComment() {
257287
if (data && data.ticket && data.ticket.locked) return;
258288

259-
await fetch(`/api/v1/ticket/comment`, {
289+
const res = await fetch(`/api/v1/ticket/comment`, {
260290
method: "POST",
261291
headers: {
262292
"Content-Type": "application/json",
@@ -267,9 +297,17 @@ export default function Ticket() {
267297
id,
268298
public: publicComment,
269299
}),
270-
})
271-
.then((res) => res.json())
272-
.then(() => refetch());
300+
}).then((res) => res.json());
301+
302+
if (!res.success) {
303+
toast({
304+
variant: "destructive",
305+
title: "Error",
306+
description: res.message || "Failed to add comment",
307+
});
308+
return;
309+
}
310+
refetch();
273311
}
274312

275313
async function deleteComment(id: string) {
@@ -326,44 +364,55 @@ export default function Ticket() {
326364
}
327365

328366
async function fetchUsers() {
329-
await fetch(`/api/v1/users/all`, {
367+
const res = await fetch(`/api/v1/users/all`, {
330368
method: "GET",
331369
headers: {
332370
"Content-Type": "application/json",
333371
Authorization: `Bearer ${token}`,
334372
},
335-
})
336-
.then((res) => res.json())
337-
.then((res) => {
338-
if (res) {
339-
setUsers(res.users);
340-
}
373+
}).then((res) => res.json());
374+
375+
if (!res.success) {
376+
toast({
377+
variant: "destructive",
378+
title: "Error",
379+
description: res.message || "Failed to fetch users",
341380
});
381+
return;
382+
}
383+
384+
if (res.users) {
385+
setUsers(res.users);
386+
}
342387
}
343388

344389
async function transferTicket() {
345390
if (data && data.ticket && data.ticket.locked) return;
391+
if (n === undefined) return;
346392

347-
if (n !== undefined) {
348-
await fetch(`/api/v1/ticket/transfer`, {
349-
method: "POST",
350-
headers: {
351-
"Content-Type": "application/json",
352-
Authorization: `Bearer ${token}`,
353-
},
354-
body: JSON.stringify({
355-
user: n.id,
356-
id,
357-
}),
358-
})
359-
.then((res) => res.json())
360-
.then((res) => {
361-
if (res.success) {
362-
setAssignedEdit(false);
363-
refetch();
364-
}
365-
});
393+
const res = await fetch(`/api/v1/ticket/transfer`, {
394+
method: "POST",
395+
headers: {
396+
"Content-Type": "application/json",
397+
Authorization: `Bearer ${token}`,
398+
},
399+
body: JSON.stringify({
400+
user: n.id,
401+
id,
402+
}),
403+
}).then((res) => res.json());
404+
405+
if (!res.success) {
406+
toast({
407+
variant: "destructive",
408+
title: "Error",
409+
description: res.message || "Failed to transfer ticket",
410+
});
411+
return;
366412
}
413+
414+
setAssignedEdit(false);
415+
refetch();
367416
}
368417

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

0 commit comments

Comments
 (0)