mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-22 14:38:19 +02:00
1 file changed
+28
-4
@@ -356,12 +356,24 @@ export default function Avoirs() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Calculate default group ID based on user role
|
||||||
|
const getDefaultGroupId = () => {
|
||||||
|
if ((user as any)?.role === 'admin') {
|
||||||
|
// Admin : groupe 1 par défaut
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
// Utilisateurs : leur groupe assigné par défaut
|
||||||
|
const userGroupIds = (user as any)?.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||||
|
return userGroupIds.length > 0 ? userGroupIds[0] : 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Initialize create form
|
// Initialize create form
|
||||||
const form = useForm<AvoirFormData>({
|
const form = useForm<AvoirFormData>({
|
||||||
resolver: zodResolver(avoirSchema),
|
resolver: zodResolver(avoirSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
supplierId: 0,
|
supplierId: 0,
|
||||||
groupId: 0,
|
groupId: getDefaultGroupId(),
|
||||||
invoiceReference: "",
|
invoiceReference: "",
|
||||||
amount: undefined,
|
amount: undefined,
|
||||||
comment: "",
|
comment: "",
|
||||||
@@ -446,6 +458,16 @@ export default function Avoirs() {
|
|||||||
|
|
||||||
// Handle status change
|
// Handle status change
|
||||||
const handleStatusChange = (avoirId: number, newStatus: string) => {
|
const handleStatusChange = (avoirId: number, newStatus: string) => {
|
||||||
|
// Empêcher les managers de mettre le statut en "Reçu"
|
||||||
|
if ((user as any)?.role === 'manager' && newStatus === 'Reçu') {
|
||||||
|
toast({
|
||||||
|
title: "Accès refusé",
|
||||||
|
description: "Vous n'avez pas les permissions pour marquer un avoir comme reçu",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const avoir = avoirs?.find(a => a?.id === avoirId);
|
const avoir = avoirs?.find(a => a?.id === avoirId);
|
||||||
if (avoir && avoir.supplierId && avoir.groupId) {
|
if (avoir && avoir.supplierId && avoir.groupId) {
|
||||||
editAvoirMutation.mutate({
|
editAvoirMutation.mutate({
|
||||||
@@ -969,7 +991,9 @@ export default function Avoirs() {
|
|||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="En attente de demande">En attente de demande</SelectItem>
|
<SelectItem value="En attente de demande">En attente de demande</SelectItem>
|
||||||
<SelectItem value="Demandé">Demandé</SelectItem>
|
<SelectItem value="Demandé">Demandé</SelectItem>
|
||||||
<SelectItem value="Reçu">Reçu</SelectItem>
|
{(user as any)?.role !== 'manager' && (
|
||||||
|
<SelectItem value="Reçu">Reçu</SelectItem>
|
||||||
|
)}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</td>
|
</td>
|
||||||
@@ -1024,8 +1048,8 @@ export default function Avoirs() {
|
|||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
{/* Upload pour avoirs "Reçu" */}
|
{/* Upload pour avoirs "Reçu" - interdit aux managers */}
|
||||||
{avoir?.status === 'Reçu' && (
|
{avoir?.status === 'Reçu' && (user as any)?.role !== 'manager' && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
Reference in new issue
Block a user