diff --git a/src/App.tsx b/src/App.tsx index f399b0c..71512a7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -45,7 +45,6 @@ import { ReplyTemplates } from './ReplyTemplates' import { GlobalSearch } from './GlobalSearch' import { CustomerContact } from './CustomerContact' import { TagList, TicketChecklist } from './TicketOrganization' -import { useTicketPage } from './useTicketPage' type Data = any export function Field({ label, children }: { label: string; children: ReactNode }) { return ( @@ -90,6 +89,8 @@ function App() { [error, setError] = useState(''), [page, setPage] = useState('inbox'), [queue, setQueue] = useState(''), + [tickets, setTickets] = useState([]), + [ticketsReady, setTicketsReady] = useState(false), [selected, setSelected] = useState(() => { const id = new URLSearchParams(location.hash.slice(1)).get('ticket') return id && Number.isSafeInteger(Number(id)) ? Number(id) : null @@ -99,30 +100,12 @@ function App() { [assignee, setAssignee] = useState(''), [tagFilter, setTagFilter] = useState(''), [sort, setSort] = useState('id'), - [pageSize, setPageSize] = useState(25), [notifications, setNotifications] = useState([]), [bell, setBell] = useState(false), [theme, setTheme] = useState(localStorage.getItem('syncova-theme') || 'system'), [compose, setCompose] = useState(false), [toast, setToast] = useState(''), [mobile, setMobile] = useState(false) - const ticketList = useTicketPage( - boot, - { - view: ['inbox', 'mine', 'waiting', 'closed'].includes(page) ? page : 'inbox', - queue, - q: search, - status, - assignee, - tag: tagFilter, - sort, - pageSize, - }, - !selected && ['inbox', 'mine', 'waiting', 'closed'].includes(page), - () => setBoot(null), - ) - const currentUser = useRef(boot?.user.id) - currentUser.current = boot?.user.id const refresh = async () => { try { const b = await api('/bootstrap') @@ -135,25 +118,22 @@ function App() { setLoading(false) } } - const loadNotifications = async () => { + const loadTickets = async () => { if (!boot) return - const userId = boot.user.id try { - const fresh = await api('/notifications') - if (currentUser.current !== userId) return - setNotifications(fresh) + setTickets(await api('/tickets')) + setNotifications(await api('/notifications')) + setTicketsReady(true) } catch (e) { - if (currentUser.current !== userId) return if ((e as Data).status === 401) { setBoot(null) + setTickets([]) setNotifications([]) + setTicketsReady(false) } setError((e as Error).message) } } - const loadTickets = async () => { - await Promise.all([ticketList.refresh(), loadNotifications()]) - } useEffect(() => { history.replaceState(null, '', selected ? '#ticket=' + selected : location.pathname) }, [selected]) @@ -161,8 +141,8 @@ function App() { refresh() }, []) useEffect(() => { - loadNotifications() - const timer = setInterval(loadNotifications, 5000) + loadTickets() + const timer = setInterval(loadTickets, 5000) return () => clearInterval(timer) }, [boot]) useEffect(() => { @@ -229,12 +209,45 @@ function App() { ) if (!boot) return const unread = notifications.filter((n) => !n.is_read).length, - counts = ticketList.counts, - rows = ticketList.items as Data[] + active = tickets.filter((t) => t.behavior !== 'closed'), + opens = active.filter((t) => !t.assignee || t.assignee === null || t.assignee === undefined), + waiting = tickets.filter((t) => t.behavior.startsWith('wait_')), + mine = active.filter((t) => t.assignee === boot.user.id) + let rows = tickets + .filter( + (t) => + (page === 'closed' + ? t.behavior === 'closed' + : page === 'waiting' + ? t.behavior.startsWith('wait_') + : page === 'mine' + ? t.assignee === boot.user.id && t.behavior !== 'closed' + : t.behavior !== 'closed') && + (!queue || t.queue_id === queue) && + (!tagFilter || + (tagFilter === 'none' + ? !t.tags?.length + : t.tags?.some((tag: Data) => tag.id === tagFilter))) && + (!status || t.behavior === status || t.status_id === status) && + (!assignee || (assignee === 'unassigned' ? !t.assignee : t.assignee === assignee)) && + `${t.subject} ${t.customer} ${t.customer_name} ${number(t.id)}` + .toLowerCase() + .includes(search.toLowerCase()), + ) + .sort((a, b) => + sort === 'oldest' + ? a.updated_at.localeCompare(b.updated_at) + : sort === 'newest' + ? b.updated_at.localeCompare(a.updated_at) + : sort === 'subject' + ? a.subject.localeCompare(b.subject) + : b.id.localeCompare(a.id), // Hier ist noch ein Fehler + ) const title = queue ? boot.queues.find((q: Data) => q.id === queue)?.name : ( { + opens: 'Offene Tickets', inbox: 'Alle Tickets', mine: 'Mir zugewiesen', waiting: 'Wartende Tickets', @@ -253,7 +266,7 @@ function App() { className="brand" onClick={(e) => { e.preventDefault() - navigate('inbox') + navigate('opens') }} > @@ -261,50 +274,47 @@ function App() { syncova -
-
TICKETS
- -
- QUEUES{' '} - {can('*', 'queue') && ( - - )} -
- +
TICKETS
+ +
+ QUEUES{' '} + {can('*', 'queue') && ( + + )}
+
- )} -
@@ -507,7 +506,7 @@ function App() {
IHR SERVICE. IM ÜBERBLICK.

{title} - {ticketList.ready ? ticketList.total : '…'} + {rows.length}

Alle Anfragen im Blick. Gemeinsam schneller zur Lösung.

@@ -519,16 +518,22 @@ function App() {
{[ - [Inbox, 'Offene Tickets', counts.open, 'Alle laufenden Anfragen', 'teal'], + [Inbox, 'Offene Tickets', active.length, 'Alle laufenden Anfragen', 'teal'], [ MessageSquare, 'Neue Anfragen', - counts.new, + active.filter((t) => t.behavior === 'new').length, 'Bereit für den ersten Kontakt', 'blue', ], - [Clock3, 'Wartende Tickets', counts.waiting, 'Kunde, Termin oder Ware', 'amber'], - [CircleCheck, 'Erledigte Tickets', counts.closed, 'Gemeinsam gelöst', 'purple'], + [Clock3, 'Wartende Tickets', waiting.length, 'Kunde, Termin oder Ware', 'amber'], + [ + CircleCheck, + 'Erledigte Tickets', + tickets.length - active.length, + 'Gemeinsam gelöst', + 'purple', + ], ].map(([Icon, label, count, sub, color]: any) => (
@@ -545,11 +550,17 @@ function App() {
))}
-
+
- {!ticketList.ready && !ticketList.error && ( + {!ticketsReady && (
Tickets werden geladen …
)} - {ticketList.ready && !rows.length && ( + {ticketsReady && !rows.length && (
Hier ist alles aufgeräumt. @@ -742,7 +753,7 @@ function App() { setSearch('') setStatus('') setAssignee('') - navigate('inbox') + navigate('opens') }} > Filter zurücksetzen @@ -750,68 +761,10 @@ function App() {
)}
- - {ticketList.ready - ? ticketList.total - ? `${(ticketList.page - 1) * pageSize + 1}–${(ticketList.page - 1) * pageSize + rows.length} von ${ticketList.total} Tickets` - : '0 Tickets' - : 'Tickets werden geladen …'} + {rows.length} Tickets angezeigt + + Automatisch aktualisiert -
- - -
@@ -1320,9 +1273,6 @@ function TicketDetail({ id, boot, can, onBack, run }: any) { : 'CC / BCC hinzufügen'}
-

- Betreff: {t.reply_subject} -

{!showCopies && (cc || bcc) && (

{cc && `CC: ${cc}`}