Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
bb99267
1
Parent(s): bd0fa52
backend stabilization
Browse files
frontend/apps/customer/src/components/ThreadView.tsx
CHANGED
|
@@ -33,7 +33,6 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 33 |
const [ticket, setTicket] = useState(initialTicket);
|
| 34 |
const [messages, setMessages] = useState<any[]>([]);
|
| 35 |
const [newMessage, setNewMessage] = useState("");
|
| 36 |
-
const [loading, setLoading] = useState(true);
|
| 37 |
const [sending, setSending] = useState(false);
|
| 38 |
|
| 39 |
// Description Edit State
|
|
@@ -48,19 +47,13 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 48 |
const [commentDraft, setCommentDraft] = useState("");
|
| 49 |
const [isSubmittingFeedback, setIsSubmittingFeedback] = useState(false);
|
| 50 |
const [showConfirmEscalate, setShowConfirmEscalate] = useState(false);
|
| 51 |
-
const [isEscalating, setIsEscalating] = useState(false);
|
| 52 |
|
| 53 |
// Sidebar States
|
| 54 |
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
|
| 55 |
const [sidebarTab, setSidebarTab] = useState<'messages' | 'files'>('messages');
|
| 56 |
|
| 57 |
-
// Message Edit State
|
| 58 |
-
const [editingMsgId, setEditingMsgId] = useState<string | null>(null);
|
| 59 |
-
const [msgEditDraft, setMsgEditDraft] = useState("");
|
| 60 |
-
|
| 61 |
const bottomRef = useRef<HTMLDivElement>(null);
|
| 62 |
const fileInputRef = useRef<HTMLInputElement>(null);
|
| 63 |
-
const descFileInputRef = useRef<HTMLInputElement>(null);
|
| 64 |
|
| 65 |
useEffect(() => {
|
| 66 |
refreshData();
|
|
@@ -71,7 +64,6 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 71 |
}, [messages]);
|
| 72 |
|
| 73 |
const refreshData = async () => {
|
| 74 |
-
setLoading(true);
|
| 75 |
try {
|
| 76 |
const [ticketResp, messagesResp] = await Promise.all([
|
| 77 |
api.get(`tickets/${initialTicket.id}/`),
|
|
@@ -82,8 +74,6 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 82 |
setMessages(messagesResp.data);
|
| 83 |
} catch (err) {
|
| 84 |
console.error("Failed to refresh data:", err);
|
| 85 |
-
} finally {
|
| 86 |
-
setLoading(false);
|
| 87 |
}
|
| 88 |
};
|
| 89 |
|
|
@@ -117,33 +107,7 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 117 |
}
|
| 118 |
};
|
| 119 |
|
| 120 |
-
const handleDeleteMessage = async (msgId: string) => {
|
| 121 |
-
if (!window.confirm("Delete this message?")) return;
|
| 122 |
-
try {
|
| 123 |
-
await api.delete(`tickets/${ticket.id}/messages/${msgId}/`);
|
| 124 |
-
setMessages(messages.filter(m => m.id !== msgId));
|
| 125 |
-
} catch (err) {
|
| 126 |
-
console.error("Failed to delete message:", err);
|
| 127 |
-
}
|
| 128 |
-
};
|
| 129 |
-
|
| 130 |
-
const startEditMessage = (msg: any) => {
|
| 131 |
-
setEditingMsgId(msg.id);
|
| 132 |
-
setMsgEditDraft(msg.content);
|
| 133 |
-
};
|
| 134 |
-
|
| 135 |
-
const handleUpdateMessage = async (msgId: string) => {
|
| 136 |
-
try {
|
| 137 |
-
const resp = await api.patch(`tickets/${ticket.id}/messages/${msgId}/`, { content: msgEditDraft });
|
| 138 |
-
setMessages(messages.map(m => m.id === msgId ? resp.data : m));
|
| 139 |
-
setEditingMsgId(null);
|
| 140 |
-
} catch (err) {
|
| 141 |
-
console.error("Failed to update message:", err);
|
| 142 |
-
}
|
| 143 |
-
};
|
| 144 |
-
|
| 145 |
const handleEscalate = async () => {
|
| 146 |
-
setIsEscalating(true);
|
| 147 |
try {
|
| 148 |
const resp = await api.post(`tickets/${ticket.id}/escalate/`);
|
| 149 |
setTicket(resp.data);
|
|
@@ -154,8 +118,6 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 154 |
} catch (err) {
|
| 155 |
console.error("Escalation failed:", err);
|
| 156 |
alert("Failed to escalate ticket. It might already be escalated.");
|
| 157 |
-
} finally {
|
| 158 |
-
setIsEscalating(false);
|
| 159 |
}
|
| 160 |
};
|
| 161 |
|
|
|
|
| 33 |
const [ticket, setTicket] = useState(initialTicket);
|
| 34 |
const [messages, setMessages] = useState<any[]>([]);
|
| 35 |
const [newMessage, setNewMessage] = useState("");
|
|
|
|
| 36 |
const [sending, setSending] = useState(false);
|
| 37 |
|
| 38 |
// Description Edit State
|
|
|
|
| 47 |
const [commentDraft, setCommentDraft] = useState("");
|
| 48 |
const [isSubmittingFeedback, setIsSubmittingFeedback] = useState(false);
|
| 49 |
const [showConfirmEscalate, setShowConfirmEscalate] = useState(false);
|
|
|
|
| 50 |
|
| 51 |
// Sidebar States
|
| 52 |
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
|
| 53 |
const [sidebarTab, setSidebarTab] = useState<'messages' | 'files'>('messages');
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
const bottomRef = useRef<HTMLDivElement>(null);
|
| 56 |
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
|
|
| 57 |
|
| 58 |
useEffect(() => {
|
| 59 |
refreshData();
|
|
|
|
| 64 |
}, [messages]);
|
| 65 |
|
| 66 |
const refreshData = async () => {
|
|
|
|
| 67 |
try {
|
| 68 |
const [ticketResp, messagesResp] = await Promise.all([
|
| 69 |
api.get(`tickets/${initialTicket.id}/`),
|
|
|
|
| 74 |
setMessages(messagesResp.data);
|
| 75 |
} catch (err) {
|
| 76 |
console.error("Failed to refresh data:", err);
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
};
|
| 79 |
|
|
|
|
| 107 |
}
|
| 108 |
};
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
const handleEscalate = async () => {
|
|
|
|
| 111 |
try {
|
| 112 |
const resp = await api.post(`tickets/${ticket.id}/escalate/`);
|
| 113 |
setTicket(resp.data);
|
|
|
|
| 118 |
} catch (err) {
|
| 119 |
console.error("Escalation failed:", err);
|
| 120 |
alert("Failed to escalate ticket. It might already be escalated.");
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
};
|
| 123 |
|