feat(waiter): English-first texts, part c: shift, log, chat, offline, notifications; language switch; guard (platform-v2 step 4.5c)

- Shift overview, order log, chat list / thread, offline + server search +
  rediscovery screens, notifications, the refused-lines sheet and the offline queue's
  reasons become keys; times and dates through useFormat() in the venue's clock.
- User menu: the other language(s) (data-testid menu-language-<lng>), saved to the
  person's profile (PATCH /api/auth/me) and the bootstrap reloaded (D-12).
- tests/no-greek.test.mjs: no Greek letter in waiter_pwa/src (the one Greek word the
  app recognises in staff messages is a \u escape).
- e2e: the test venue is English: waiter / browser / android use the English texts;
  waiter.mjs +3 (English by default, switch to Greek at once and saved, after reload);
  android bundle checks print what they saw when they fail.
- Pack README: the waiter texts rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 04:31:48 +02:00
co-authored by Claude Opus 5.5
parent 2c4f78af47
commit f8d91e7fae
16 changed files with 493 additions and 201 deletions
+32 -27
View File
@@ -2,12 +2,13 @@ import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import client from '../api/client'
import { apiError } from '../api/errors'
import { useFormat, useTranslation } from '@xenia/i18n'
import useAuthStore from '../store/authStore'
import useChatStore from '../store/chatStore'
// ─── Relative time (Greek) ────────────────────────────────────────────────────
function relativeTime(dateStr) {
function relativeTime(dateStr, t, formatDate) {
if (!dateStr) return ''
const date = new Date(dateStr)
const now = new Date()
@@ -15,9 +16,9 @@ function relativeTime(dateStr) {
const diffMin = Math.floor(diffMs / 60_000)
const diffHours = Math.floor(diffMs / 3_600_000)
if (diffMin < 1) return 'τώρα'
if (diffMin < 60) return `${diffMin}λ`
if (diffHours < 24) return `${diffHours}ω`
if (diffMin < 1) return t('chat.now')
if (diffMin < 60) return t('common.minutesShort', { m: diffMin })
if (diffHours < 24) return t('common.hoursShort', { h: diffHours })
const yesterday = new Date(now)
yesterday.setDate(yesterday.getDate() - 1)
@@ -25,9 +26,9 @@ function relativeTime(dateStr) {
date.getDate() === yesterday.getDate() &&
date.getMonth() === yesterday.getMonth() &&
date.getFullYear() === yesterday.getFullYear()
) return 'χθες'
) return t('chat.yesterday')
return date.toLocaleDateString('el-GR', { day: '2-digit', month: '2-digit' })
return formatDate(date, 'dateShort')
}
// ─── Avatar ───────────────────────────────────────────────────────────────────
@@ -53,18 +54,20 @@ function Avatar({ label, size = 44, isGroup = false }) {
// ─── Conversation row ─────────────────────────────────────────────────────────
function ConvRow({ conv, currentUserId, onClick }) {
const { t } = useTranslation('waiter')
const { formatDate } = useFormat()
const isGroup = conv.type === 'group'
const title = isGroup
? (conv.name || 'Ομάδα')
: (conv.participants?.find(p => p.user_id !== currentUserId)?.username || 'Άγνωστος')
? (conv.name || t('chat.group'))
: (conv.participants?.find(p => p.user_id !== currentUserId)?.username || t('chat.unknown'))
const lastMsg = conv.last_message
const preview = lastMsg
? lastMsg.is_deleted
? 'Το μήνυμα διαγράφηκε'
? t('chat.deleted')
: lastMsg.body
: 'Δεν υπάρχουν μηνύματα'
: t('chat.noMessages')
const timestamp = lastMsg?.sent_at || conv.created_at
const hasUnread = (conv.unread_count || 0) > 0
@@ -91,7 +94,7 @@ function ConvRow({ conv, currentUserId, onClick }) {
{title}
</span>
<span style={{ fontSize: 12, color: 'var(--muted)', flexShrink: 0 }}>
{relativeTime(timestamp)}
{relativeTime(timestamp, t, formatDate)}
</span>
</div>
<div style={{
@@ -125,6 +128,7 @@ function ConvRow({ conv, currentUserId, onClick }) {
// ─── New Chat bottom drawer ───────────────────────────────────────────────────
function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
const { t } = useTranslation('waiter')
const [staff, setStaff] = useState([])
const [loading, setLoading] = useState(true)
const [mode, setMode] = useState('picker') // 'picker' | 'group_name' | 'group_pick'
@@ -136,7 +140,7 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
useEffect(() => {
client.get('/api/chat/users')
.then(r => setStaff((r.data || []).filter(u => u.id !== currentUserId)))
.catch(() => setError('Αποτυχία φόρτωσης χρηστών'))
.catch(() => setError(t('chat.usersFailed')))
.finally(() => setLoading(false))
}, [currentUserId])
@@ -150,7 +154,7 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
})
onConversationCreated(res.data)
} catch (e) {
setError(apiError(e, 'Σφάλμα δημιουργίας συνομιλίας'))
setError(apiError(e, t('chat.createFailed')))
setCreating(false)
}
}
@@ -167,7 +171,7 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
})
onConversationCreated(res.data)
} catch (e) {
setError(apiError(e, 'Σφάλμα δημιουργίας ομάδας'))
setError(apiError(e, t('chat.groupFailed')))
setCreating(false)
}
}
@@ -185,7 +189,7 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
{mode === 'picker' && (
<>
<h2 className="modal-title" style={{ marginBottom: 16 }}>Νέα Συνομιλία</h2>
<h2 className="modal-title" style={{ marginBottom: 16 }}>{t('chat.new')}</h2>
{/* New Group option */}
<button
@@ -204,18 +208,18 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
}}>
👥
</div>
<span style={{ fontSize: 15, fontWeight: 700, color: 'var(--accent)' }}>Νέα Ομάδα</span>
<span style={{ fontSize: 15, fontWeight: 700, color: 'var(--accent)' }}>{t('chat.newGroup')}</span>
</button>
<div style={{ flex: 1, overflowY: 'auto', marginTop: 4 }}>
{loading && (
<p style={{ textAlign: 'center', color: 'var(--muted)', padding: 24, fontSize: 14 }}>
Φόρτωση…
{t('common.loading')}
</p>
)}
{!loading && staff.length === 0 && !error && (
<p style={{ textAlign: 'center', color: 'var(--muted)', padding: 24, fontSize: 14 }}>
Δεν υπάρχει άλλο προσωπικό
{t('chat.noStaff')}
</p>
)}
{staff.map(u => (
@@ -257,14 +261,14 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
<path d="M12.5 15l-5-5 5-5" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>
</button>
<h2 className="modal-title" style={{ margin: 0 }}>Όνομα Ομάδας</h2>
<h2 className="modal-title" style={{ margin: 0 }}>{t('chat.groupName')}</h2>
</div>
<input
autoFocus
value={groupName}
onChange={e => setGroupName(e.target.value)}
onKeyDown={e => e.key === 'Enter' && groupName.trim() && setMode('group_pick')}
placeholder="π.χ. Βραδινή βάρδια"
placeholder={t('chat.groupNamePlaceholder')}
style={{
width: '100%', padding: '12px 14px',
background: 'var(--bg3)', border: '1px solid var(--border)',
@@ -278,7 +282,7 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
disabled={!groupName.trim()}
onClick={() => groupName.trim() && setMode('group_pick')}
>
Επόμενο
{t('chat.next')}
</button>
</>
)}
@@ -294,10 +298,10 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
<path d="M12.5 15l-5-5 5-5" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>
</button>
<h2 className="modal-title" style={{ margin: 0 }}>Επιλογή Μελών</h2>
<h2 className="modal-title" style={{ margin: 0 }}>{t('chat.pickMembers')}</h2>
</div>
<p style={{ fontSize: 13, color: 'var(--muted)', marginBottom: 12 }}>
Ομάδα: <strong style={{ color: 'var(--text)' }}>{groupName}</strong>
{t('chat.groupLabel')} <strong style={{ color: 'var(--text)' }}>{groupName}</strong>
</p>
<div style={{ flex: 1, overflowY: 'auto', marginBottom: 12 }}>
@@ -347,7 +351,7 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
disabled={creating}
onClick={createGroup}
>
{creating ? 'Δημιουργία…' : `Δημιουργία Ομάδας${selectedIds.length > 0 ? ` (${selectedIds.length})` : ''}`}
{creating ? t('chat.creating') : selectedIds.length > 0 ? t('chat.createGroupCount', { count: selectedIds.length }) : t('chat.createGroup')}
</button>
</>
)}
@@ -363,6 +367,7 @@ function NewChatDrawer({ currentUserId, onClose, onConversationCreated }) {
// ─── Main page ────────────────────────────────────────────────────────────────
export default function ChatListPage() {
const { t } = useTranslation('waiter')
const navigate = useNavigate()
const { user } = useAuthStore()
const { conversations, setConversations, upsertConversation } = useChatStore()
@@ -414,7 +419,7 @@ export default function ChatListPage() {
</svg>
</div>
<span style={{ fontSize: 15, fontWeight: 700, color: 'var(--accent)' }}>
Νέα Συνομιλία
{t('chat.new')}
</span>
</button>
@@ -430,7 +435,7 @@ export default function ChatListPage() {
{/* ── Regular conversations ────────────────────────────────────── */}
{loading && (
<div style={{ textAlign: 'center', padding: 40, color: 'var(--muted)', fontSize: 14 }}>
Φόρτωση…
{t('common.loading')}
</div>
)}
@@ -441,7 +446,7 @@ export default function ChatListPage() {
}}>
<span style={{ fontSize: 40 }}>💬</span>
<p style={{ fontSize: 15, color: 'var(--muted)', textAlign: 'center', lineHeight: 1.5, margin: 0 }}>
Πατήστε «Νέα Συνομιλία» για να ξεκινήσετε μια συζήτηση.
{t('chat.startHint')}
</p>
</div>
)}
+25 -23
View File
@@ -1,17 +1,14 @@
import { useEffect, useRef, useState, useCallback } from 'react'
import { useNavigate, useParams } from 'react-router-dom'
import client from '../api/client'
import { useFormat, useTranslation } from '@xenia/i18n'
import useAuthStore from '../store/authStore'
import useChatStore from '../store/chatStore'
// ─── Helpers ──────────────────────────────────────────────────────────────────
function formatTime(dateStr) {
if (!dateStr) return ''
return new Date(dateStr).toLocaleTimeString('el-GR', { hour: '2-digit', minute: '2-digit' })
}
function formatDateLabel(dateStr) {
function formatDateLabel(dateStr, t, formatDateTime) {
const date = new Date(dateStr)
const now = new Date()
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate())
@@ -19,9 +16,9 @@ function formatDateLabel(dateStr) {
yesterday.setDate(yesterday.getDate() - 1)
const d = new Date(date.getFullYear(), date.getMonth(), date.getDate())
if (d.getTime() === today.getTime()) return 'Σήμερα'
if (d.getTime() === yesterday.getTime()) return 'Χθες'
return date.toLocaleDateString('el-GR', { weekday: 'long', day: 'numeric', month: 'long' })
if (d.getTime() === today.getTime()) return t('chat.today')
if (d.getTime() === yesterday.getTime()) return t('chat.yesterdayCap')
return formatDateTime(date, { weekday: 'long', day: 'numeric', month: 'long' })
}
function sameDay(a, b) {
@@ -34,6 +31,8 @@ function sameDay(a, b) {
// ─── Message bubble ───────────────────────────────────────────────────────────
function MessageBubble({ msg, isOwn, showSender, isGroup }) {
const { t } = useTranslation('waiter')
const { formatTime } = useFormat()
if (msg.is_deleted) {
return (
<div style={{
@@ -44,7 +43,7 @@ function MessageBubble({ msg, isOwn, showSender, isGroup }) {
background: 'var(--bg3)',
}}>
<span style={{ fontSize: 13, color: 'var(--muted)', fontStyle: 'italic' }}>
Το μήνυμα διαγράφηκε
{t('chat.deleted')}
</span>
</div>
)
@@ -142,6 +141,7 @@ function AutoTextarea({ value, onChange, onSubmit, placeholder }) {
// ─── Leave confirmation modal ─────────────────────────────────────────────────
function LeaveModal({ onConfirm, onCancel }) {
const { t } = useTranslation('waiter')
return (
<div className="modal-overlay" onClick={onCancel}>
<div
@@ -150,12 +150,12 @@ function LeaveModal({ onConfirm, onCancel }) {
style={{ maxHeight: 'auto' }}
>
<div className="modal-handle" />
<h2 className="modal-title" style={{ marginBottom: 8 }}>Αποχώρηση από ομάδα;</h2>
<h2 className="modal-title" style={{ marginBottom: 8 }}>{t('chat.leaveTitle')}</h2>
<p style={{ fontSize: 14, color: 'var(--muted)', lineHeight: 1.5, marginBottom: 20 }}>
Δεν θα λαμβάνετε πλέον μηνύματα από αυτή την ομάδα.
{t('chat.leaveBody')}
</p>
<div style={{ display: 'flex', gap: 10 }}>
<button className="btn btn--secondary" style={{ flex: 1 }} onClick={onCancel}>Ακύρωση</button>
<button className="btn btn--secondary" style={{ flex: 1 }} onClick={onCancel}>{t('common.cancel')}</button>
<button
style={{
flex: 1, height: 44, borderRadius: 12, border: 'none',
@@ -164,7 +164,7 @@ function LeaveModal({ onConfirm, onCancel }) {
}}
onClick={onConfirm}
>
Αποχώρηση
{t('chat.leave')}
</button>
</div>
</div>
@@ -175,6 +175,8 @@ function LeaveModal({ onConfirm, onCancel }) {
// ─── Main page ────────────────────────────────────────────────────────────────
export default function ChatThreadPage() {
const { t } = useTranslation('waiter')
const { formatDateTime } = useFormat()
const { conversationId } = useParams()
const navigate = useNavigate()
const { user } = useAuthStore()
@@ -205,8 +207,8 @@ export default function ChatThreadPage() {
const isGroup = conv?.type === 'group'
const title = isGroup
? (conv?.name || 'Ομάδα')
: (conv?.participants?.find(p => p.user_id !== user?.id)?.username || 'Συνομιλία')
? (conv?.name || t('chat.group'))
: (conv?.participants?.find(p => p.user_id !== user?.id)?.username || t('chat.conversation'))
// ── Mark as read ─────────────────────────────────────────────────────────────
@@ -418,7 +420,7 @@ export default function ChatThreadPage() {
if (!prev || !sameDay(prev.sent_at, msg.sent_at)) {
items.push(
<DateSeparator key={`date-${msg.id}`} label={formatDateLabel(msg.sent_at)} />
<DateSeparator key={`date-${msg.id}`} label={formatDateLabel(msg.sent_at, t, formatDateTime)} />
)
}
@@ -458,7 +460,7 @@ export default function ChatThreadPage() {
<svg width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M12.5 15l-5-5 5-5" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>
Πίσω
{t('common.back')}
</button>
<div style={{ flex: 1, textAlign: 'center', minWidth: 0 }}>
@@ -470,7 +472,7 @@ export default function ChatThreadPage() {
</span>
{isGroup && (
<span style={{ fontSize: 11, color: 'var(--muted)', display: 'block', marginTop: -2 }}>
{(conv?.participants || []).length} μέλη
{t('chat.members', { count: (conv?.participants || []).length })}
</span>
)}
</div>
@@ -484,7 +486,7 @@ export default function ChatThreadPage() {
padding: '0 4px', minHeight: 44, borderRadius: 8, flexShrink: 0,
}}
>
Αποχώρηση
{t('chat.leave')}
</button>
) : (
<div style={{ width: 72, flexShrink: 0 }} />
@@ -504,13 +506,13 @@ export default function ChatThreadPage() {
>
{loadingMore && (
<div style={{ textAlign: 'center', padding: '8px 0', color: 'var(--muted)', fontSize: 13 }}>
Φόρτωση παλαιότερων…
{t('chat.loadingOlder')}
</div>
)}
{initialLoad && (
<div style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<span style={{ color: 'var(--muted)', fontSize: 14 }}>Φόρτωση…</span>
<span style={{ color: 'var(--muted)', fontSize: 14 }}>{t('common.loading')}</span>
</div>
)}
@@ -521,7 +523,7 @@ export default function ChatThreadPage() {
}}>
<span style={{ fontSize: 40 }}>💬</span>
<p style={{ fontSize: 15, color: 'var(--muted)', textAlign: 'center', lineHeight: 1.5 }}>
Δεν υπάρχουν μηνύματα ακόμα.{'\n'}Πείτε γεια!
{t('chat.emptyThread')}{'\n'}{t('chat.sayHi')}
</p>
</div>
)}
@@ -542,7 +544,7 @@ export default function ChatThreadPage() {
value={inputText}
onChange={e => setInputText(e.target.value)}
onSubmit={sendMessage}
placeholder="Γράψτε μήνυμα…"
placeholder={t('chat.placeholder')}
/>
<button
+8 -6
View File
@@ -2,11 +2,13 @@ import client from '../api/client'
import { deliveryMode } from '../config/server'
import { canRediscover, rediscover } from '../native/autoRediscover'
import { useState } from 'react'
import { useTranslation } from '@xenia/i18n'
// Shown at /offline, and (plan step 4.1) instead of the whole app when the server can't be
// reached on a start with no cached bootstrap (the app retries by itself and then opens the
// screen the address asks for).
export default function OfflinePage() {
const { t } = useTranslation('waiter')
const [checking, setChecking] = useState(false)
const [search, setSearch] = useState(null) // null | { done, total } | 'not-found'
@@ -37,12 +39,12 @@ export default function OfflinePage() {
<div className="page page--centered">
<div style={{ textAlign: 'center', maxWidth: 300 }}>
<p style={{ fontSize: 48, marginBottom: 16 }}>📡</p>
<h2 style={{ color: '#e2e8f0', marginBottom: 8 }}>Δεν υπάρχει σύνδεση</h2>
<h2 style={{ color: '#e2e8f0', marginBottom: 8 }}>{t('offline.title')}</h2>
<p style={{ color: '#64748b', marginBottom: 32 }}>
Δεν είναι δυνατή η επικοινωνία με το σύστημα. Ελέγξτε τη σύνδεση WiFi.
{t('offline.body')}
</p>
<button className="btn btn--primary btn--lg" onClick={retry} disabled={checking || searching}>
{checking ? 'Έλεγχος…' : 'Επανάληψη'}
{checking ? t('venues.checking') : t('common.retry')}
</button>
{canRediscover() && (
<button
@@ -51,12 +53,12 @@ export default function OfflinePage() {
onClick={searchNetwork}
disabled={searching}
>
{searching ? `Αναζήτηση… ${search.done}/${search.total}` : 'Αναζήτηση server στο δίκτυο'}
{searching ? t('offline.searching', { done: search.done, total: search.total }) : t('offline.search')}
</button>
)}
{search === 'not-found' && (
<p style={{ color: '#94a3b8', fontSize: 13, marginTop: 12, lineHeight: 1.45 }}>
Ο server δεν βρέθηκε στο δίκτυο. Ελέγξτε ότι είναι αναμμένος, ή σαρώστε ξανά το QR από τον διαχειριστή.
{t('offline.notFound')}
</p>
)}
{deliveryMode() === 'native' && (
@@ -66,7 +68,7 @@ export default function OfflinePage() {
onClick={() => { window.location.href = '/venues' }}
disabled={searching}
>
Αλλαγή καταστήματος
{t('offline.changeVenue')}
</button>
)}
</div>
+53 -57
View File
@@ -2,25 +2,12 @@ import { useState, useEffect, useCallback, useRef } from 'react'
import { useSearchParams } from 'react-router-dom'
import AppShell from '../components/AppShell'
import client from '../api/client'
import { useFormat, useTranslation } from '@xenia/i18n'
import { money as fmtPrice } from '../i18n'
// ── helpers ───────────────────────────────────────────────────────────────────
function fmtTime(iso) {
if (!iso) return '—'
return new Date(iso).toLocaleTimeString('el-GR', { hour: '2-digit', minute: '2-digit' })
}
function fmtDateTime(iso) {
if (!iso) return '—'
return new Date(iso).toLocaleString('el-GR', {
day: '2-digit', month: '2-digit',
hour: '2-digit', minute: '2-digit',
})
}
function fmtPrice(n) {
return '€' + parseFloat(n || 0).toFixed(2)
}
// times in the venue's clock and the language's format: useFormat() in each component (4.5)
// ── icons ─────────────────────────────────────────────────────────────────────
@@ -86,6 +73,8 @@ function FilterIcon() {
// ── action sheet — long-press on detailed cards ───────────────────────────────
function PrintActionSheet({ order, onRetry, onCancel, onClose, busy }) {
const { t } = useTranslation('waiter')
const { formatTime: fmtTime } = useFormat()
return (
<div
onClick={onClose}
@@ -106,13 +95,13 @@ function PrintActionSheet({ order, onRetry, onCancel, onClose, busy }) {
>
<div style={{ width: 40, height: 4, borderRadius: 2, background: 'var(--border)', margin: '0 auto 16px' }} />
<div style={{ fontSize: 15, fontWeight: 700, color: 'var(--text)', marginBottom: 4 }}>
Πρόβλημα Εκτύπωσης
{t('log.printProblem')}
</div>
<div style={{ fontSize: 13, color: 'var(--muted)', marginBottom: 20 }}>
Παραγγελία #{order.id} · {order.table_name} · {fmtTime(order.opened_at)}
{t('log.orderLine', { id: order.id, table: order.table_name, time: fmtTime(order.opened_at) })}
{order.print_retry_count > 0 && (
<span style={{ marginLeft: 8, color: '#f59e0b' }}>
{order.print_retry_count} επανάληψ{order.print_retry_count === 1 ? 'η' : 'εις'}
{t('log.retries', { count: order.print_retry_count })}
</span>
)}
</div>
@@ -127,7 +116,7 @@ function PrintActionSheet({ order, onRetry, onCancel, onClose, busy }) {
opacity: busy ? 0.6 : 1,
}}
>
{busy ? 'Αποστολή…' : 'Εκτύπωση Τώρα'}
{busy ? t('add.sending') : t('log.printNow')}
</button>
<button
onClick={onCancel}
@@ -140,7 +129,7 @@ function PrintActionSheet({ order, onRetry, onCancel, onClose, busy }) {
opacity: busy ? 0.6 : 1,
}}
>
Ακύρωση Εκτύπωσης
{t('log.cancelPrint')}
</button>
<button
onClick={onClose}
@@ -150,7 +139,7 @@ function PrintActionSheet({ order, onRetry, onCancel, onClose, busy }) {
fontSize: 15, color: 'var(--muted)', cursor: 'pointer',
}}
>
Κλείσιμο
{t('common.close')}
</button>
</div>
</div>
@@ -161,6 +150,7 @@ function PrintActionSheet({ order, onRetry, onCancel, onClose, busy }) {
// ── filter sheet ──────────────────────────────────────────────────────────────
function FilterSheet({ filter, dateFrom, dateTo, onApply, onClose }) {
const { t } = useTranslation('waiter')
const [localFilter, setLocalFilter] = useState(filter)
const [localFrom, setLocalFrom] = useState(dateFrom)
const [localTo, setLocalTo] = useState(dateTo)
@@ -184,18 +174,18 @@ function FilterSheet({ filter, dateFrom, dateTo, onApply, onClose }) {
}}
>
<div style={{ width: 40, height: 4, borderRadius: 2, background: 'var(--border)', margin: '0 auto 20px' }} />
<div style={{ fontSize: 15, fontWeight: 700, color: 'var(--text)', marginBottom: 16 }}>Φίλτρα</div>
<div style={{ fontSize: 15, fontWeight: 700, color: 'var(--text)', marginBottom: 16 }}>{t('tables.filter.title')}</div>
{/* Status filter */}
<div style={{ marginBottom: 20 }}>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--muted)', marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.05em' }}>
Κατάσταση
{t('tables.filter.status')}
</div>
<div style={{ display: 'flex', gap: 8 }}>
{[
{ value: 'all', label: 'Όλες' },
{ value: 'success', label: 'Επιτυχής' },
{ value: 'failed', label: 'Αποτυχημένη' },
{ value: 'all', label: t('orders.chips.all') },
{ value: 'success', label: t('log.ok') },
{ value: 'failed', label: t('log.failedF') },
].map(opt => (
<button
key={opt.value}
@@ -218,11 +208,11 @@ function FilterSheet({ filter, dateFrom, dateTo, onApply, onClose }) {
{/* Date range */}
<div style={{ marginBottom: 24 }}>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--muted)', marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.05em' }}>
Εύρος ημερομηνίας/ώρας
{t('log.range')}
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
<span style={{ fontSize: 12, color: 'var(--muted)', width: 28 }}>Από</span>
<span style={{ fontSize: 12, color: 'var(--muted)', width: 28 }}>{t('log.from')}</span>
<input
type="datetime-local"
value={localFrom}
@@ -236,7 +226,7 @@ function FilterSheet({ filter, dateFrom, dateTo, onApply, onClose }) {
/>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
<span style={{ fontSize: 12, color: 'var(--muted)', width: 28 }}>Έως</span>
<span style={{ fontSize: 12, color: 'var(--muted)', width: 28 }}>{t('log.to')}</span>
<input
type="datetime-local"
value={localTo}
@@ -257,7 +247,7 @@ function FilterSheet({ filter, dateFrom, dateTo, onApply, onClose }) {
background: 'none', border: 'none', cursor: 'pointer', padding: '2px 0',
}}
>
Καθαρισμός ημερομηνίας
{t('log.clearDates')}
</button>
)}
</div>
@@ -271,7 +261,7 @@ function FilterSheet({ filter, dateFrom, dateTo, onApply, onClose }) {
fontSize: 15, fontWeight: 700, cursor: 'pointer',
}}
>
Εφαρμογή
{t('common.apply')}
</button>
</div>
</div>
@@ -281,6 +271,7 @@ function FilterSheet({ filter, dateFrom, dateTo, onApply, onClose }) {
// ── compact card (click = expand inline, expanded shows action buttons) ────────
function CompactCard({ order, expanded, onToggle, onRetry, onCancel, busy }) {
const { t } = useTranslation('waiter')
const isPending = order.print_status === 'pending'
return (
@@ -315,7 +306,7 @@ function CompactCard({ order, expanded, onToggle, onRetry, onCancel, busy }) {
{/* Row 2: item count | total */}
<div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 5 }}>
<span style={{ fontSize: 12, color: 'var(--muted)' }}>
{order.items.length} αντ.
{t('log.itemsShort', { count: order.items.length })}
</span>
<span style={{ fontSize: 12, fontWeight: 600, color: 'var(--text)' }}>
{fmtPrice(order.total)}
@@ -343,11 +334,11 @@ function CompactCard({ order, expanded, onToggle, onRetry, onCancel, busy }) {
<div style={{ borderTop: '1px dashed var(--border)', margin: '0 14px' }} />
<div style={{ padding: '8px 14px', display: 'flex', flexDirection: 'column', gap: 4 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span style={{ fontSize: 14, fontWeight: 600, color: 'var(--muted)' }}>Σύνολο</span>
<span style={{ fontSize: 14, fontWeight: 600, color: 'var(--muted)' }}>{t('common.total')}</span>
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
{isPending && order.print_retry_count > 0 && (
<span style={{ fontSize: 11, color: '#f59e0b' }}>
{order.print_retry_count} επανάληψ{order.print_retry_count === 1 ? 'η' : 'εις'}
{t('log.retries', { count: order.print_retry_count })}
</span>
)}
<span style={{ fontSize: 14, fontWeight: 700, color: 'var(--text)' }}>{fmtPrice(order.total)}</span>
@@ -355,9 +346,9 @@ function CompactCard({ order, expanded, onToggle, onRetry, onCancel, busy }) {
</div>
{order.fiscal_status && (
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12 }}>
<span style={{ color: 'var(--muted)' }}>Φορολογική εκτύπωση</span>
<span style={{ color: 'var(--muted)' }}>{t('log.fiscal')}</span>
<span style={{ fontWeight: 600, color: order.fiscal_status === 'success' ? '#22c55e' : order.fiscal_status === 'pending' ? '#f59e0b' : '#ef4444' }}>
{order.fiscal_status === 'success' ? 'Επιτυχής' : order.fiscal_status === 'pending' ? 'Εκκρεμεί…' : 'Αποτυχία'}
{order.fiscal_status === 'success' ? t('log.ok') : order.fiscal_status === 'pending' ? t('log.pending') : t('log.failed')}
</span>
</div>
)}
@@ -376,7 +367,7 @@ function CompactCard({ order, expanded, onToggle, onRetry, onCancel, busy }) {
opacity: busy ? 0.6 : 1,
}}
>
{busy ? 'Αποστολή…' : 'Εκτύπωση Τώρα'}
{busy ? t('add.sending') : t('log.printNow')}
</button>
<button
onClick={() => onCancel(order)}
@@ -389,7 +380,7 @@ function CompactCard({ order, expanded, onToggle, onRetry, onCancel, busy }) {
opacity: busy ? 0.6 : 1,
}}
>
Ακύρωση
{t('log.cancel')}
</button>
</div>
</>
@@ -403,6 +394,9 @@ function CompactCard({ order, expanded, onToggle, onRetry, onCancel, busy }) {
// ── detailed card (long-press = action sheet) ─────────────────────────────────
function DetailedCard({ order, onLongPress }) {
const { t } = useTranslation('waiter')
const { formatDateTime: fmtDateTime } = useFormat()
const { formatTime: fmtTime } = useFormat()
const isPending = order.print_status === 'pending'
const pressTimer = useRef(null)
@@ -450,22 +444,22 @@ function DetailedCard({ order, onLongPress }) {
{/* Meta rows */}
<div style={{ padding: '10px 14px', display: 'flex', flexDirection: 'column', gap: 5 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12 }}>
<span style={{ color: 'var(--muted)' }}>Παραγγέλθηκε</span>
<span style={{ color: 'var(--muted)' }}>{t('summary.ordered')}</span>
<span style={{ color: 'var(--text)', fontWeight: 500 }}>{fmtDateTime(order.opened_at)}</span>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12 }}>
<span style={{ color: 'var(--muted)' }}>Εκτύπωση</span>
<span style={{ color: 'var(--muted)' }}>{t('log.print')}</span>
<span style={{ fontWeight: 600, color: isPending ? '#ef4444' : '#22c55e' }}>
{isPending
? `Εκκρεμεί (${order.print_retry_count} επαν.)`
? t('log.pendingRetries', { count: order.print_retry_count })
: `OK ${fmtTime(order.print_attempted_at)}`}
</span>
</div>
{order.fiscal_status && (
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12 }}>
<span style={{ color: 'var(--muted)' }}>Φορολογική εκτύπωση</span>
<span style={{ color: 'var(--muted)' }}>{t('log.fiscal')}</span>
<span style={{ fontWeight: 600, color: order.fiscal_status === 'success' ? '#22c55e' : order.fiscal_status === 'pending' ? '#f59e0b' : '#ef4444' }}>
{order.fiscal_status === 'success' ? 'Επιτυχής' : order.fiscal_status === 'pending' ? 'Εκκρεμεί…' : 'Αποτυχία'}
{order.fiscal_status === 'success' ? t('log.ok') : order.fiscal_status === 'pending' ? t('log.pending') : t('log.failed')}
</span>
</div>
)}
@@ -493,13 +487,13 @@ function DetailedCard({ order, onLongPress }) {
{/* Total */}
<div style={{ display: 'flex', justifyContent: 'space-between', padding: '8px 14px', fontSize: 14 }}>
<span style={{ color: 'var(--muted)', fontWeight: 600 }}>Σύνολο</span>
<span style={{ color: 'var(--muted)', fontWeight: 600 }}>{t('common.total')}</span>
<span style={{ color: 'var(--text)', fontWeight: 700 }}>{fmtPrice(order.total)}</span>
</div>
{isPending && (
<div style={{ padding: '0 14px 10px', textAlign: 'center' }}>
<span style={{ fontSize: 11, color: 'var(--muted)' }}>Κρατήστε πατημένο για επιλογές</span>
<span style={{ fontSize: 11, color: 'var(--muted)' }}>{t('log.holdForOptions')}</span>
</div>
)}
</div>
@@ -509,6 +503,8 @@ function DetailedCard({ order, onLongPress }) {
// ── main page ─────────────────────────────────────────────────────────────────
export default function OrderLogPage() {
const { t } = useTranslation('waiter')
const { formatDateTime } = useFormat()
const [searchParams] = useSearchParams()
const initialFilter = searchParams.get('filter') === 'failed' ? 'failed' : 'all'
@@ -605,7 +601,7 @@ export default function OrderLogPage() {
const hasActiveFilters = filter !== 'all' || !!dateFrom || !!dateTo
return (
<AppShell title="Αρχ. Παραγγ.">
<AppShell title={t('log.titleShort')}>
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden', position: 'relative' }}>
{/* Toolbar */}
@@ -617,7 +613,7 @@ export default function OrderLogPage() {
}}>
<input
type="search"
placeholder="Τραπέζι, #παραγγελία, αντικείμενο…"
placeholder={t('log.searchPlaceholder')}
value={search}
onChange={e => setSearch(e.target.value)}
style={{
@@ -636,7 +632,7 @@ export default function OrderLogPage() {
display: 'flex', alignItems: 'center', justifyContent: 'center',
cursor: 'pointer',
}}
title={view === 'compact' ? 'Λεπτομερής προβολή' : 'Συμπαγής προβολή'}
title={view === 'compact' ? t('log.detailedView') : t('log.compactView')}
>
{view === 'compact' ? <DetailedIcon active={false} /> : <CompactIcon active={false} />}
</button>
@@ -656,7 +652,7 @@ export default function OrderLogPage() {
<path d="M12 8v4M12 16h.01" stroke="#ef4444" strokeWidth="2" strokeLinecap="round"/>
</svg>
<span style={{ fontSize: 13, color: '#ef4444', fontWeight: 600 }}>
{pendingCount} παραγγελί{pendingCount !== 1 ? 'ες' : 'α'} με πρόβλημα εκτύπωσης
{t('log.printProblems', { count: pendingCount })}
</span>
</div>
)}
@@ -676,24 +672,24 @@ export default function OrderLogPage() {
color: filter === 'failed' ? '#ef4444' : '#22c55e',
fontWeight: 600,
}}>
{filter === 'failed' ? 'Αποτυχημένη εκτύπωση' : 'Επιτυχής εκτύπωση'}
{filter === 'failed' ? t('log.printFailed') : t('log.printOk')}
</span>
)}
{dateFrom && (
<span style={{ fontSize: 12, padding: '3px 10px', borderRadius: 999, background: 'var(--bg3)', color: 'var(--muted)' }}>
Από {new Date(dateFrom).toLocaleString('el-GR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' })}
{t('log.from')} {formatDateTime(new Date(dateFrom), 'datetimeShort')}
</span>
)}
{dateTo && (
<span style={{ fontSize: 12, padding: '3px 10px', borderRadius: 999, background: 'var(--bg3)', color: 'var(--muted)' }}>
Έως {new Date(dateTo).toLocaleString('el-GR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' })}
{t('log.to')} {formatDateTime(new Date(dateTo), 'datetimeShort')}
</span>
)}
<button
onClick={() => { setFilter('all'); setDateFrom(''); setDateTo('') }}
style={{ fontSize: 12, color: 'var(--muted)', background: 'none', border: 'none', cursor: 'pointer', padding: '3px 6px' }}
>
✕ Καθαρισμός
✕ {t('common.clear')}
</button>
</div>
)}
@@ -701,11 +697,11 @@ export default function OrderLogPage() {
{/* List */}
<div style={{ flex: 1, overflowY: 'auto', padding: '12px 14px 80px', display: 'flex', flexDirection: 'column', gap: 8 }}>
{loading && (
<p style={{ textAlign: 'center', color: 'var(--muted)', padding: '40px 0', fontSize: 14 }}>Φόρτωση…</p>
<p style={{ textAlign: 'center', color: 'var(--muted)', padding: '40px 0', fontSize: 14 }}>{t('common.loading')}</p>
)}
{!loading && filtered.length === 0 && (
<p style={{ textAlign: 'center', color: 'var(--muted)', padding: '40px 0', fontSize: 14 }}>
{search || hasActiveFilters ? 'Δεν βρέθηκαν παραγγελίες' : 'Δεν υπάρχουν παραγγελίες σε αυτή τη βάρδια'}
{search || hasActiveFilters ? t('log.noneFound') : t('log.noneThisShift')}
</p>
)}
{filtered.map(order =>
@@ -744,7 +740,7 @@ export default function OrderLogPage() {
display: 'flex', alignItems: 'center', justifyContent: 'center',
zIndex: 10,
}}
title="Φίλτρα"
title={t('tables.filter.title')}
>
<FilterIcon />
{hasActiveFilters && (
+28 -29
View File
@@ -1,27 +1,22 @@
import { useQuery } from '@tanstack/react-query'
import AppShell from '../components/AppShell'
import client from '../api/client'
import { useFormat, useTranslation } from '@xenia/i18n'
import { money as fmtEuro, tw } from '../i18n'
import { getVenueSettings } from '../api/venueSettings'
// ── helpers ───────────────────────────────────────────────────────────────────
function fmtTime(iso) {
if (!iso) return '—'
return new Date(iso).toLocaleTimeString('el-GR', { hour: '2-digit', minute: '2-digit' })
}
function fmtDuration(seconds) {
if (seconds == null || seconds < 0) return '—'
const h = Math.floor(seconds / 3600)
const m = Math.floor((seconds % 3600) / 60)
if (h === 0) return `${m}λ`
if (m === 0) return `${h}ω`
return `${h}ω ${m}λ`
if (h === 0) return tw('common.minutesShort', { m })
if (m === 0) return tw('common.hoursShort', { h })
return tw('common.hoursMinutesShort', { h, m })
}
function fmtEuro(n) {
return '€' + parseFloat(n || 0).toFixed(2)
}
function sinceSeconds(isoStart) {
if (!isoStart) return 0
@@ -101,6 +96,8 @@ function PerHourChart({ title, data, accent = 'var(--accent)' }) {
// ── breaks timeline ───────────────────────────────────────────────────────────
function BreakRow({ brk, index }) {
const { t } = useTranslation('waiter')
const { formatTime: fmtTime } = useFormat()
const dur = breakDurationSeconds(brk)
const active = !brk.ended_at
return (
@@ -118,7 +115,7 @@ function BreakRow({ brk, index }) {
}}>{index + 1}</div>
<div style={{ flex: 1 }}>
<div style={{ fontSize: 13, fontWeight: 600, color: 'var(--text)' }}>
{fmtTime(brk.started_at)} – {active ? 'Τώρα' : fmtTime(brk.ended_at)}
{fmtTime(brk.started_at)} – {active ? t('shiftPage.now') : fmtTime(brk.ended_at)}
</div>
<div style={{ fontSize: 11, color: 'var(--muted)', marginTop: 1 }}>
{fmtDuration(dur)}
@@ -128,7 +125,7 @@ function BreakRow({ brk, index }) {
<span style={{
fontSize: 10, fontWeight: 700, padding: '3px 8px', borderRadius: 999,
background: '#f97316', color: 'white',
}}>ΕΝΕΡΓΟ</span>
}}>{t('venues.active')}</span>
)}
</div>
)
@@ -137,6 +134,8 @@ function BreakRow({ brk, index }) {
// ── main page ─────────────────────────────────────────────────────────────────
export default function ShiftOverviewPage() {
const { t } = useTranslation('waiter')
const { formatTime: fmtTime } = useFormat()
const { data: shift, isLoading: shiftLoading } = useQuery({
queryKey: ['my-shift'],
queryFn: () => client.get('/api/shifts/my').then(r => r.data),
@@ -164,7 +163,7 @@ export default function ShiftOverviewPage() {
return (
<AppShell title="Shift Overview">
<div style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--muted)', fontSize: 14 }}>
Φόρτωση…
{t('common.loading')}
</div>
</AppShell>
)
@@ -175,8 +174,8 @@ export default function ShiftOverviewPage() {
<AppShell title="Shift Overview">
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 12, padding: 24, textAlign: 'center' }}>
<div style={{ fontSize: 40 }}>⏸</div>
<div style={{ fontSize: 16, fontWeight: 700, color: 'var(--text)' }}>Δεν υπάρχει ενεργή βάρδια</div>
<div style={{ fontSize: 13, color: 'var(--muted)' }}>Ξεκινήστε βάρδια για να δείτε στατιστικά.</div>
<div style={{ fontSize: 16, fontWeight: 700, color: 'var(--text)' }}>{t('shiftPage.none')}</div>
<div style={{ fontSize: 13, color: 'var(--muted)' }}>{t('shiftPage.noneSub')}</div>
</div>
</AppShell>
)
@@ -219,9 +218,9 @@ export default function ShiftOverviewPage() {
}}>
<span style={{ fontSize: 20 }}>☕</span>
<div>
<div style={{ fontSize: 14, fontWeight: 700, color: '#f97316' }}>Σε διάλειμμα</div>
<div style={{ fontSize: 14, fontWeight: 700, color: '#f97316' }}>{t('shiftPage.onBreak')}</div>
<div style={{ fontSize: 12, color: 'var(--muted)', marginTop: 1 }}>
από {fmtTime(activeBreak.started_at)} · {fmtDuration(breakDurationSeconds(activeBreak))} μέχρι τώρα
{t('shiftPage.breakSince', { time: fmtTime(activeBreak.started_at), duration: fmtDuration(breakDurationSeconds(activeBreak)) })}
</div>
</div>
</div>
@@ -229,18 +228,18 @@ export default function ShiftOverviewPage() {
{/* Hero stats grid */}
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10, marginBottom: 20 }}>
<StatCard label="Έναρξη" value={fmtTime(shift.started_at)} />
<StatCard label="Ώρες Εργασίας" value={fmtDuration(workedSec)} sub={`${fmtDuration(totalBreakSec)} διαλείμματα`} />
<StatCard label="Αρχ. Μετρητά" value={fmtEuro(shift.starting_cash)} />
<StatCard label={t('shiftPage.start')} value={fmtTime(shift.started_at)} />
<StatCard label={t('shiftPage.worked')} value={fmtDuration(workedSec)} sub={t('shiftPage.breaksSub', { duration: fmtDuration(totalBreakSec) })} />
<StatCard label={t('shiftPage.startCash')} value={fmtEuro(shift.starting_cash)} />
{!hideRevenue && (
<StatCard label="Είσπραξη" value={fmtEuro(shift.total_collected)} accent="var(--success, #22c55e)" />
<StatCard label={t('shiftPage.collected')} value={fmtEuro(shift.total_collected)} accent="var(--success, #22c55e)" />
)}
{!hideRevenue && (
<StatCard label="Παραδ. Ποσό" value={fmtEuro(shift.net_to_deliver)} sub="Αρχ. + Είσπραξη" accent="var(--accent)" />
<StatCard label={t('shiftPage.toHandIn')} value={fmtEuro(shift.net_to_deliver)} sub={t('shiftPage.toHandInSub')} accent="var(--accent)" />
)}
<StatCard label="Ανοιχτά Τραπέζια" value={String(openOrders.length)} sub="τρέχουσες παραγγελίες" />
<StatCard label="Είδη (ανοιχτά)" value={String(totalItems)} />
<StatCard label="Διαλείμματα" value={String((shift.breaks || []).length)} sub={`${fmtDuration(totalBreakSec)} σύνολο`} />
<StatCard label={t('shiftPage.openTables')} value={String(openOrders.length)} sub={t('shiftPage.openTablesSub')} />
<StatCard label={t('shiftPage.items')} value={String(totalItems)} />
<StatCard label={t('shiftPage.breaks')} value={String((shift.breaks || []).length)} sub={t('shiftPage.totalSub', { duration: fmtDuration(totalBreakSec) })} />
</div>
{/* Per-hour charts */}
@@ -249,9 +248,9 @@ export default function ShiftOverviewPage() {
background: 'var(--bg2)', border: '1px solid var(--border)',
borderRadius: 16, padding: '16px 18px', marginBottom: 20,
}}>
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text)', marginBottom: 16 }}>Ανά Ώρα</div>
<PerHourChart title="Παραγγελίες" data={ordersByHour} />
<PerHourChart title="Είδη" data={itemsByHour} />
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text)', marginBottom: 16 }}>{t('shiftPage.perHour')}</div>
<PerHourChart title={t('nav.orders')} data={ordersByHour} />
<PerHourChart title={t('shiftPage.itemsShort')} data={itemsByHour} />
</div>
)}
@@ -259,7 +258,7 @@ export default function ShiftOverviewPage() {
{(shift.breaks || []).length > 0 && (
<div>
<div style={{ fontSize: 12, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.5, marginBottom: 10 }}>
Διαλείμματα ({shift.breaks.length})
{t('shiftPage.breaksCount', { count: shift.breaks.length })}
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{shift.breaks.map((b, i) => <BreakRow key={b.id} brk={b} index={i} />)}