diff --git a/frontend/src/pages/TimeClockPage.jsx b/frontend/src/pages/TimeClockPage.jsx index 4b7c73d..6772582 100644 --- a/frontend/src/pages/TimeClockPage.jsx +++ b/frontend/src/pages/TimeClockPage.jsx @@ -3,25 +3,14 @@ import { BrowserQRCodeReader } from '@zxing/browser'; import { timeApi } from '../api/time'; import { useAuth } from '../context/useAuth'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import { Alert, AlertDescription } from '@/components/ui/alert'; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from '@/components/ui/table'; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { Badge } from '@/components/ui/badge'; import ConfirmDialog from '@/components/ConfirmDialog'; -import { - Dialog, - DialogContent, - DialogHeader, - DialogTitle, -} from '@/components/ui/dialog'; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Calendar } from '@/components/ui/calendar'; import { Popover, @@ -63,7 +52,6 @@ const formatDateLabel = (value) => { }); }; - const DatePicker = ({ value, onChange, @@ -87,7 +75,6 @@ const DatePicker = ({ } > - {selectedDate ? formatDateLabel(value) : placeholder} @@ -111,7 +98,6 @@ const DatePicker = ({ ); }; - const TimePicker = ({ value, onChange, @@ -122,23 +108,18 @@ const TimePicker = ({ const [hours = '', minutes = ''] = value ? value.split(':') : []; const setTimePart = (part, nextValue) => { - const nextHours = - part === 'hours' ? nextValue : hours || '00'; - - const nextMinutes = - part === 'minutes' ? nextValue : minutes || '00'; + const nextHours = part === 'hours' ? nextValue : hours || '00'; + const nextMinutes = part === 'minutes' ? nextValue : minutes || '00'; onChange(`${nextHours}:${nextMinutes}`); }; - const hourOptions = Array.from( - { length: 24 }, - (_, index) => String(index).padStart(2, '0'), + const hourOptions = Array.from({ length: 24 }, (_, index) => + String(index).padStart(2, '0') ); - const minuteOptions = Array.from( - { length: 60 }, - (_, index) => String(index).padStart(2, '0'), + const minuteOptions = Array.from({ length: 60 }, (_, index) => + String(index).padStart(2, '0') ); return ( @@ -153,21 +134,14 @@ const TimePicker = ({ } > - {value || placeholder} - +
- - Choisir une heure - - + Choisir une heure {value || '--:--'} @@ -178,7 +152,6 @@ const TimePicker = ({

Heure

-
{hourOptions.map((hour) => ( -

- Si le navigateur a déjà - bloqué la caméra, autorisez-la - dans les paramètres du site - puis cliquez ici pour - réessayer. + Si le navigateur a déjà bloqué la caméra, autorisez-la dans les paramètres du site puis cliquez ici pour réessayer.

)} - {scanMessage && ( - - - {scanMessage} - + + {scanMessage} )} - {scanConflict && ( - - Conflit de pointage - + Conflit de pointage - -

- {scanConflict.message} -

- - - +

{scanConflict.message}

+ -
- - - - - + />
- - ) : ( -
-
- -
- - - - setNewEntry({ - ...newEntry, - date: value, - }) - } - /> -
- - -
- - - - setNewEntry({ - ...newEntry, - end_date: - value, - }) - } - /> -
- - -
- - - - setNewEntry({ - ...newEntry, - start_time: - value, - }) - } - /> -
- - -
- - - - setNewEntry({ - ...newEntry, - end_time: - value, - }) - } - /> -
+
+ + + setEditForm({ ...editForm, end_time: value }) + } + />
- - - - - )} - - - )} - - - {/* ================================================== - POINTAGE QR - ================================================== */} +
+
+ + +
+ + ) : ( +
+
+
+ + + setNewEntry({ ...newEntry, date: value }) + } + /> +
+
+ + + setNewEntry({ ...newEntry, end_date: value }) + } + /> +
+
+ + + setNewEntry({ ...newEntry, start_time: value }) + } + /> +
+
+ + + setNewEntry({ ...newEntry, end_time: value }) + } + /> +
+
+ +
+ )} +
+
+ )}
- + {/* Pointage uniquement disponible sur mobile */}
{ if (open) { - setIsScannerDialogOpen( - true, - ); + setIsScannerDialogOpen(true); } else { closeScanner(); } }} > - - - - Aperçu de la caméra - + Aperçu de la caméra - -
- - {!isAdmin && ( + {/* Sur ordinateur, le pointage est volontairement indisponible */} + {!isAdmin &&

- Le pointage est - indisponible sur ordinateur. + Le pointage est indisponible sur ordinateur.

- )} - - - {/* ================================================== - HISTORIQUE - ================================================== */} + } - - {showAllUsers - ? 'Historique des pointages' - : `Historique des pointages de${ - selectedUser - ? ` ${getUserLabel( - selectedUser, - )}` - : '' - }`} - + Historique des pointages - - {loading ? ( -

- Chargement des - pointages... -

- ) : displayedTimeEntries.length === - 0 ? ( -

- Aucun pointage - enregistré -

+

Chargement des pointages...

+ ) : displayedTimeEntries.length === 0 ? ( +

Aucun pointage enregistré

) : (
- - {isAdmin && ( - - Nom - - )} - - - Date - - - - Entrée - - - - Sortie - - - - Durée - - - {isAdmin && ( - - Actions - - )} - + {isAdmin && Utilisateur} + Date + Entrée + Sortie + Durée + {isAdmin && Actions} - - - {displayedTimeEntries.map( - (entry) => ( - - - {isAdmin && ( - - {entry.user - ? getUserLabel( - entry.user, - ) - : 'Utilisateur inconnu'} - - )} - - + {getDisplayTimeEntries() + .filter( + (entry) => + !isAdmin || + showAllUsers || + getEntryUserId(entry) === String(selectedUserId), + ) + .map((entry) => ( + + {isAdmin && {getEntryUserLabel(entry)}} + {formatDate(entry.date)} + {formatTime(entry.start_time)} + {formatTime(entry.end_time)} + {formatDuration(entry.duration)} + {isAdmin && ( - {formatDate( - entry.date, - )} +
+ + handleDeleteEntry(entry.id)}> + + +
- - - - {formatTime( - entry.start_time, - )} - - - - - {formatTime( - entry.end_time, - )} - - - - - - {formatDuration( - entry.duration, - )} - - - - - {isAdmin && ( - -
- - - - - - handleDeleteEntry( - entry.id, - ) - } - > - - - -
-
- )} - -
- ), - )} + )} +
+ ))}
)}
-