Refactor MachineCard component and update API endpoints
This commit is contained in:
@@ -80,7 +80,7 @@ export default function ProtectedLayout() {
|
||||
options={{
|
||||
title: 'Macchine',
|
||||
tabBarIcon: ({ color, size }) => <Car pointerEvents="none" color={color} size={24} />,
|
||||
href: authState.user?.isAdmin ? undefined : null,
|
||||
href: !authState.user?.isAdmin ? undefined : null,
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
|
||||
@@ -65,7 +65,7 @@ export default function MachineScreen() {
|
||||
const onScan = async (data: string) => {
|
||||
console.log('Scanned data:', data);
|
||||
try {
|
||||
const response = await api.post('/machine-attendance/scan', { uuid: data });
|
||||
const response = await api.post('/machine-attendance/in', { uuid: data });
|
||||
if (response.data?.success) {
|
||||
console.log('Scan data sent successfully:', response.data);
|
||||
fetchAttendances();
|
||||
@@ -84,28 +84,6 @@ export default function MachineScreen() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleExitPress = (item: MachineAttendanceItem) => {
|
||||
alert.showConfirm(
|
||||
'Conferma Uscita',
|
||||
`Vuoi davvero registrare l'uscita da ${item.name}?`,
|
||||
[
|
||||
{ text: 'Annulla', onPress: () => {}, style: 'cancel' },
|
||||
{ text: 'Conferma', style: 'default', onPress: async () => {
|
||||
try {
|
||||
const response = await api.post('/machine-attendance/out', { uuid: item.machine_uuid });
|
||||
if (response.data?.success) {
|
||||
fetchAttendances();
|
||||
} else {
|
||||
alert.showAlert('error', 'Errore', response.data?.message || 'Impossibile registrare l\'uscita.');
|
||||
}
|
||||
} catch (error) {
|
||||
alert.showAlert('error', 'Errore', 'Impossibile registrare l\'uscita. Riprova più tardi.');
|
||||
}
|
||||
}}
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
if (isLoading && !refreshing) {
|
||||
return <LoadingScreen />;
|
||||
}
|
||||
@@ -192,7 +170,7 @@ export default function MachineScreen() {
|
||||
) : (
|
||||
<View>
|
||||
{attendances.map((item, index) => (
|
||||
<MachineCard key={index} item={item} onExitPress={handleExitPress} />
|
||||
<MachineCard key={index} item={item} />
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
|
||||
@@ -99,13 +99,13 @@ export default function PermitsScreen() {
|
||||
const deletePermitRequest = async (id: number, itemRef?: React.ElementRef<typeof Swipeable> | null) => {
|
||||
try {
|
||||
itemRef?.close();
|
||||
const res = await api.get(`/request/delete-request?id=${id}`);
|
||||
if (res.data.code === 200) {
|
||||
const res = await api.post('/request/delete', { id });
|
||||
if (res.data?.success) {
|
||||
// Optimistic update
|
||||
setPermits(prevPermits => prevPermits.filter(p => p.id !== id));
|
||||
alert.showAlert('success', 'Richiesta eliminata', 'La richiesta è stata eliminata con successo.');
|
||||
} else {
|
||||
alert.showAlert('error', 'Errore', 'Impossibile eliminare la richiesta.');
|
||||
alert.showAlert('error', 'Errore', res.data?.message || 'Impossibile eliminare la richiesta.');
|
||||
}
|
||||
// Refresh
|
||||
fetchPermits();
|
||||
|
||||
Reference in New Issue
Block a user