Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Support): allow anytime disable auto-close #310

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions client/src/screens/conductor/support/Ticket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ const SupportTicketView = () => {
},
});

const disableAutoCloseMutation = useMutation({
mutationFn: () => updateTicket({ autoCloseSilenced: true }),
const toggleAutoCloseMutation = useMutation({
mutationFn: (newStatus: boolean) =>
updateTicket({ autoCloseSilenced: newStatus }),
onSuccess: () => {
queryClient.invalidateQueries(["ticket", id]);
},
Expand Down Expand Up @@ -152,9 +153,9 @@ const SupportTicketView = () => {
setLoading(true);
const res = await axios.patch(`/support/ticket/${id}`, {
...ticket,
autoCloseSilenced: autoCloseSilenced ?? false,
...(status && { status }),
...(priority && { priority: priority.toLowerCase() }),
...(autoCloseSilenced && { autoCloseSilenced }),
});

if (res.data.err) {
Expand Down Expand Up @@ -228,6 +229,15 @@ const SupportTicketView = () => {
)}
{["open", "in_progress"].includes(ticket?.status ?? "") && (
<>
<Button
onClick={() =>
toggleAutoCloseMutation.mutateAsync(!ticket?.autoCloseSilenced)
}
loading={loading || isFetching}
>
<Icon name="shield alternate" />
{ticket?.autoCloseSilenced ? "Enable" : "Disable"} Auto-Close
</Button>
<Dropdown
text={`Priority: ${capitalizeFirstLetter(
ticket?.priority ?? "medium"
Expand All @@ -237,6 +247,7 @@ const SupportTicketView = () => {
labeled
button
className="icon"
loading={loading || isFetching}
>
<Dropdown.Menu>
{changePriorityOptions.map((opt) => (
Expand Down Expand Up @@ -308,7 +319,7 @@ const SupportTicketView = () => {
<TicketAutoCloseWarning
ticket={ticket}
onDisableAutoClose={() =>
disableAutoCloseMutation.mutateAsync()
toggleAutoCloseMutation.mutateAsync(false)
}
/>
)}
Expand Down
48 changes: 19 additions & 29 deletions server/api/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,16 @@ async function assignTicket(
});
}

const newAssignees = assigned.filter((a) => !ticket.assignedUUIDs?.includes(a));
const newAssignees = assigned.filter(
(a) => !ticket.assignedUUIDs?.includes(a)
);

const assignees = await User.find({ uuid: { $in: assigned } }).orFail();
const newAssigneeEmails = assignees.map((a) => {
if(newAssignees.includes(a.uuid)) return a.email;
}).filter(e => e) as string[];
const newAssigneeEmails = assignees
.map((a) => {
if (newAssignees.includes(a.uuid)) return a.email;
})
.filter((e) => e) as string[];

// Check that ticket is open or in progress
if (!["open", "in_progress"].includes(ticket.status)) {
Expand Down Expand Up @@ -476,10 +480,10 @@ async function assignTicket(
).orFail();

// If no new assignees to notify (or assignee was removed), return
if(newAssigneeEmails.length === 0) {
if (newAssigneeEmails.length === 0) {
return res.send({
err: false,
ticket
ticket,
});
}

Expand Down Expand Up @@ -766,29 +770,8 @@ async function updateTicket(

const ticket = await SupportTicket.findOne({ uuid }).orFail();

// If status/priority is the same, just return the ticket
if (
ticket.status === status &&
ticket.priority === priority &&
!autoCloseSilenced
) {
return res.send({
err: false,
ticket,
});
}

// If autoCloseSilenced is true, update the ticket and return
if (autoCloseSilenced) {
await SupportTicket.updateOne(
{ uuid },
{
autoCloseSilenced: true,
autoCloseTriggered: false,
autoCloseDate: null,
}
).orFail();

// If status/priority/autoClose is the same, just return the ticket
if (ticket.status === status && ticket.priority === priority && autoCloseSilenced === ticket.autoCloseSilenced) {
return res.send({
err: false,
ticket,
Expand Down Expand Up @@ -834,13 +817,20 @@ async function updateTicket(
updatedFeed.push(feedEntry);
}

const autoCloseStatusChanged = autoCloseSilenced !== ticket.autoCloseSilenced;

await SupportTicket.updateOne(
{ uuid },
{
priority,
status,
feed: updatedFeed,
timeClosed: status === "closed" ? new Date().toISOString() : undefined, // if status is closed, set timeClosed to now
autoCloseSilenced: autoCloseSilenced,
...(autoCloseStatusChanged && {
autoCloseTriggered: false,
autoCloseDate: null,
})
}
).orFail();

Expand Down
Loading