Spaces:
Paused
Paused
Download frontend/apps/customer/src/components/NewTicketModal.tsx from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 9.4 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/customer/src/components/NewTicketModal.tsx
- Command line
-
hf download hf://spaces/TeamError404/nexus/frontend/apps/customer/src/components/NewTicketModal.tsx
-
curl -L -o NewTicketModal.tsx https://huggingface.co/spaces/TeamError404/nexus/resolve/main/frontend/apps/customer/src/components/NewTicketModal.tsx
9.4 kB
| import React, { useState, useRef } from 'react'; | |
| import { api, getFileIcon } from '@nexus/shared'; | |
| const COLORS = { | |
| brand: "#1E40AF", | |
| gray50: "#F9FAFB", | |
| brandLight: "#EFF6FF", | |
| gray200: "#E5E7EB", | |
| gray400: "#9CA3AF", | |
| gray500: "#6B7280", | |
| gray600: "#4B5563", | |
| gray800: "#1F2937", | |
| gray900: "#111827", | |
| }; | |
| interface NewTicketModalProps { | |
| onClose: () => void; | |
| onCreate: (form: any) => void; | |
| } | |
| export const NewTicketModal: React.FC<NewTicketModalProps> = ({ onClose, onCreate }) => { | |
| const [form, setForm] = useState({ title: "", category: "Software", priority: "P2", description: "" }); | |
| const [attachments, setAttachments] = useState<any[]>([]); | |
| const [isUploading, setIsUploading] = useState(false); | |
| const [submitted, setSubmitted] = useState(false); | |
| const [loading, setLoading] = useState(false); | |
| const fileInputRef = useRef<HTMLInputElement>(null); | |
| const handleFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => { | |
| const files = e.target.files; | |
| if (!files) return; | |
| for (let i = 0; i < files.length; i++) { | |
| const file = files[i]; | |
| setIsUploading(true); | |
| const formData = new FormData(); | |
| formData.append("file", file); | |
| try { | |
| const resp = await api.post(`tickets/upload/`, formData, { | |
| headers: { 'Content-Type': 'multipart/form-data' } | |
| }); | |
| const backendBase = api.defaults.baseURL?.endsWith('/') ? api.defaults.baseURL : api.defaults.baseURL + '/'; | |
| const downloadUrl = `${backendBase}tickets/attachments/${resp.data.id}/download/`; | |
| setAttachments(prev => [...prev, { ...resp.data, downloadUrl }]); | |
| } catch (err) { | |
| console.error("Upload failed", err); | |
| alert(`Failed to upload ${file.name}`); | |
| } finally { | |
| setIsUploading(false); | |
| } | |
| } | |
| if (fileInputRef.current) fileInputRef.current.value = ""; | |
| }; | |
| const removeAttachment = (id: string) => { | |
| setAttachments(prev => prev.filter(a => a.id !== id)); | |
| }; | |
| const handleSubmit = async () => { | |
| if (!form.title || !form.description) return; | |
| setLoading(true); | |
| try { | |
| const payload = { | |
| ...form, | |
| attachment_ids: attachments.map(a => a.id) | |
| }; | |
| await onCreate(payload); | |
| setSubmitted(true); | |
| setTimeout(onClose, 2000); | |
| } catch (err) { | |
| console.error("Submission failed", err); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| return ( | |
| <div style={{ position: "fixed", inset: 0, background: "rgba(0,0,0,0.4)", zIndex: 100, display: "flex", alignItems: "center", justifyContent: "center" }}> | |
| <div style={{ background: "#fff", borderRadius: 14, padding: "28px 32px", width: 540, maxWidth: "90vw", boxShadow: "0 20px 60px rgba(0,0,0,0.15)" }}> | |
| {submitted ? ( | |
| <div style={{ textAlign: "center", padding: "20px 0" }}> | |
| <div style={{ fontSize: 40, marginBottom: 12 }}>✓</div> | |
| <div style={{ fontSize: 16, fontWeight: 600, color: COLORS.gray800, marginBottom: 6 }}>Ticket submitted!</div> | |
| <div style={{ fontSize: 13, color: COLORS.gray500 }}>Our AI is triaging your request now...</div> | |
| </div> | |
| ) : ( | |
| <> | |
| <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }}> | |
| <div style={{ fontSize: 16, fontWeight: 600, color: COLORS.gray900 }}>Create new ticket</div> | |
| <button onClick={onClose} style={{ background: "none", border: "none", cursor: "pointer", fontSize: 18, color: COLORS.gray400, lineHeight: 1 }}>×</button> | |
| </div> | |
| <div style={{ display: "flex", flexDirection: "column", gap: 16 }}> | |
| <div> | |
| <label style={{ display: "block", fontSize: 12, fontWeight: 600, color: COLORS.gray600, marginBottom: 6 }}>Subject *</label> | |
| <input value={form.title} onChange={e => setForm(f => ({ ...f, title: e.target.value }))} placeholder="Briefly describe your issue" style={{ width: "100%", padding: "9px 12px", border: `1px solid ${COLORS.gray200}`, borderRadius: 8, fontSize: 13, outline: "none", boxSizing: "border-box", color: COLORS.gray900, background: "#fff" }} /> | |
| </div> | |
| <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14 }}> | |
| <div> | |
| <label style={{ display: "block", fontSize: 12, fontWeight: 600, color: COLORS.gray600, marginBottom: 6 }}>Category</label> | |
| <select value={form.category} onChange={e => setForm(f => ({ ...f, category: e.target.value }))} style={{ width: "100%", padding: "9px 12px", border: `1px solid ${COLORS.gray200}`, borderRadius: 8, fontSize: 13, outline: "none", color: COLORS.gray900, background: "#fff" }}> | |
| {["Network", "Software", "Hardware", "Security", "Email", "Other"].map(c => <option key={c}>{c}</option>)} | |
| </select> | |
| </div> | |
| <div> | |
| <label style={{ display: "block", fontSize: 12, fontWeight: 600, color: COLORS.gray600, marginBottom: 6 }}>Priority</label> | |
| <select value={form.priority} onChange={e => setForm(f => ({ ...f, priority: e.target.value }))} style={{ width: "100%", padding: "9px 12px", border: `1px solid ${COLORS.gray200}`, borderRadius: 8, fontSize: 13, outline: "none", color: COLORS.gray900, background: "#fff" }}> | |
| <option value="P3">Low (P3)</option> | |
| <option value="P2">Medium (P2)</option> | |
| <option value="P1">High (P1)</option> | |
| <option value="P0">Urgent (P0)</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div> | |
| <label style={{ display: "block", fontSize: 12, fontWeight: 600, color: COLORS.gray600, marginBottom: 6 }}>Description *</label> | |
| <textarea value={form.description} onChange={e => setForm(f => ({ ...f, description: e.target.value }))} placeholder="Provide as much detail as possible..." style={{ width: "100%", padding: "9px 12px", border: `1px solid ${COLORS.gray200}`, borderRadius: 8, fontSize: 13, outline: "none", minHeight: 80, resize: "vertical", fontFamily: "inherit", boxSizing: "border-box", color: COLORS.gray900, background: "#fff" }} /> | |
| </div> | |
| {/* Attachments Section */} | |
| <div> | |
| <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 }}> | |
| <label style={{ fontSize: 11, fontWeight: 800, color: COLORS.gray400, textTransform: "uppercase" }}>Attachments</label> | |
| <button | |
| onClick={() => fileInputRef.current?.click()} | |
| disabled={isUploading} | |
| style={{ background: "none", border: "none", color: COLORS.brand, fontSize: 12, fontWeight: 700, cursor: "pointer", display: "flex", alignItems: "center", gap: 4 }} | |
| > | |
| <span>🖇️</span> Add Files | |
| </button> | |
| <input type="file" ref={fileInputRef} onChange={handleFileSelect} multiple style={{ display: "none" }} /> | |
| </div> | |
| {attachments.length > 0 && ( | |
| <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginBottom: 8 }}> | |
| {attachments.map(att => ( | |
| <div key={att.id} style={{ display: "flex", alignItems: "center", gap: 6, background: COLORS.gray50, border: `1px solid ${COLORS.gray200}`, borderRadius: 6, padding: "4px 10px", fontSize: 12 }}> | |
| <span>{getFileIcon(att.filename)}</span> | |
| <span style={{ maxWidth: 120, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{att.filename}</span> | |
| <button onClick={() => removeAttachment(att.id)} style={{ background: "none", border: "none", color: COLORS.gray400, cursor: "pointer", padding: 0, fontSize: 14 }}>×</button> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| {isUploading && <div style={{ fontSize: 11, color: COLORS.brand }}>Uploading...</div>} | |
| </div> | |
| <div style={{ background: COLORS.brandLight, borderRadius: 8, padding: "10px 14px", fontSize: 12, color: COLORS.brand, display: "flex", gap: 8 }}> | |
| <span>✦</span> Our AI will automatically triage, categorise, and suggest solutions for your ticket. | |
| </div> | |
| <div style={{ display: "flex", gap: 10, justifyContent: "flex-end" }}> | |
| <button onClick={onClose} disabled={loading} style={{ padding: "9px 18px", background: "none", border: `1px solid ${COLORS.gray200}`, borderRadius: 8, fontSize: 13, cursor: loading ? "default" : "pointer", color: COLORS.gray600 }}>Cancel</button> | |
| <button onClick={handleSubmit} disabled={loading} style={{ padding: "9px 20px", background: loading ? COLORS.gray400 : COLORS.brand, color: "#fff", border: "none", borderRadius: 8, fontSize: 13, fontWeight: 600, cursor: loading ? "default" : "pointer" }}>{loading ? 'Creating...' : 'Submit ticket'}</button> | |
| </div> | |
| </div> | |
| </> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| }; | |