Fixed opening tickets
This commit is contained in:
1 parent
2f5b17b13e
commit
8fb88e9349
3 files changed
+25
-3
No files matched your search
@@ -338,6 +338,8 @@ export const api = {
|
|||||||
request<
|
request<
|
||||||
ApiResponse<{
|
ApiResponse<{
|
||||||
guildId: string;
|
guildId: string;
|
||||||
|
departmentsEnabled?: boolean;
|
||||||
|
configuredDepartments?: { id: string; name: string; emoji?: string }[];
|
||||||
tickets: {
|
tickets: {
|
||||||
ticket_id: string;
|
ticket_id: string;
|
||||||
user_id: string;
|
user_id: string;
|
||||||
|
|||||||
@@ -147,9 +147,10 @@ export default function Tickets() {
|
|||||||
api.getConfigJson("supportbot")
|
api.getConfigJson("supportbot")
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res && res.data && typeof res.data === "object") {
|
if (res && res.data && typeof res.data === "object") {
|
||||||
|
const ticketType = getByPath(res.data, "Ticket.TicketType");
|
||||||
const deptVal = getByPath(res.data, "Ticket.DepartmentSystem.Enabled");
|
const deptVal = getByPath(res.data, "Ticket.DepartmentSystem.Enabled");
|
||||||
if (typeof deptVal === "boolean") {
|
if (typeof deptVal === "boolean") {
|
||||||
setDepartmentsEnabled(deptVal);
|
setDepartmentsEnabled(ticketType !== "threads" && deptVal);
|
||||||
}
|
}
|
||||||
const deptsObj = getByPath(res.data, "Ticket.DepartmentSystem.Departments");
|
const deptsObj = getByPath(res.data, "Ticket.DepartmentSystem.Departments");
|
||||||
if (deptsObj && typeof deptsObj === "object") {
|
if (deptsObj && typeof deptsObj === "object") {
|
||||||
@@ -160,7 +161,10 @@ export default function Tickets() {
|
|||||||
}));
|
}));
|
||||||
if (deptsList.length > 0) {
|
if (deptsList.length > 0) {
|
||||||
setConfiguredDepartments(deptsList);
|
setConfiguredDepartments(deptsList);
|
||||||
setCreateDept(deptsList[0].id);
|
setCreateDept((prev) => {
|
||||||
|
const exists = deptsList.some((d) => d.id === prev);
|
||||||
|
return exists ? prev : deptsList[0].id;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,7 +255,7 @@ export default function Tickets() {
|
|||||||
setCreating(true);
|
setCreating(true);
|
||||||
try {
|
try {
|
||||||
const res = await api.createTicket({
|
const res = await api.createTicket({
|
||||||
department: departmentsEnabled ? createDept : "general",
|
department: departmentsEnabled ? createDept : undefined,
|
||||||
subject: createSubject.trim(),
|
subject: createSubject.trim(),
|
||||||
userId: createUserId.trim() || undefined,
|
userId: createUserId.trim() || undefined,
|
||||||
});
|
});
|
||||||
@@ -311,6 +315,16 @@ export default function Tickets() {
|
|||||||
if (res.data) {
|
if (res.data) {
|
||||||
setGuildId(res.data.guildId);
|
setGuildId(res.data.guildId);
|
||||||
setList(res.data.tickets.sort((a, b) => b.created_at - a.created_at));
|
setList(res.data.tickets.sort((a, b) => b.created_at - a.created_at));
|
||||||
|
if (typeof res.data.departmentsEnabled === "boolean") {
|
||||||
|
setDepartmentsEnabled(res.data.departmentsEnabled);
|
||||||
|
}
|
||||||
|
if (Array.isArray(res.data.configuredDepartments) && res.data.configuredDepartments.length > 0) {
|
||||||
|
setConfiguredDepartments(res.data.configuredDepartments);
|
||||||
|
setCreateDept((prev) => {
|
||||||
|
const exists = res.data?.configuredDepartments?.some((d) => d.id === prev);
|
||||||
|
return exists ? prev : res.data!.configuredDepartments![0].id;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : "Failed to load open tickets");
|
setError(err instanceof Error ? err.message : "Failed to load open tickets");
|
||||||
|
|||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "SupportBot-Dashboard",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user