mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-18 20:57:40 +02:00
Merge pull request #31 from R0m1k3/1.1
Fix issues for employee role in customer order management
This commit is contained in:
1 file changed
+16
-12
@@ -40,10 +40,12 @@ import { CustomerOrderForm } from "@/components/CustomerOrderForm";
|
|||||||
import { CustomerOrderDetails } from "@/components/CustomerOrderDetails";
|
import { CustomerOrderDetails } from "@/components/CustomerOrderDetails";
|
||||||
import { ConfirmationModal } from "@/components/ConfirmationModal";
|
import { ConfirmationModal } from "@/components/ConfirmationModal";
|
||||||
import { useStore } from "@/components/Layout";
|
import { useStore } from "@/components/Layout";
|
||||||
|
import { usePermissions } from "@shared/permissions";
|
||||||
|
|
||||||
export default function CustomerOrders() {
|
export default function CustomerOrders() {
|
||||||
const { user } = useAuthUnified();
|
const { user } = useAuthUnified();
|
||||||
const { selectedStoreId } = useStore();
|
const { selectedStoreId } = useStore();
|
||||||
|
const permissions = usePermissions(user?.role);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [showCreateModal, setShowCreateModal] = useState(false);
|
const [showCreateModal, setShowCreateModal] = useState(false);
|
||||||
const [showEditModal, setShowEditModal] = useState(false);
|
const [showEditModal, setShowEditModal] = useState(false);
|
||||||
@@ -63,7 +65,7 @@ export default function CustomerOrders() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Fetch suppliers for filter
|
// Fetch suppliers for filter
|
||||||
const { data: suppliers = [] } = useQuery({
|
const { data: suppliers = [] } = useQuery<any[]>({
|
||||||
queryKey: ['/api/suppliers'],
|
queryKey: ['/api/suppliers'],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -78,8 +80,8 @@ export default function CustomerOrders() {
|
|||||||
mutationFn: (data: any) => apiRequest('/api/customer-orders', 'POST', data),
|
mutationFn: (data: any) => apiRequest('/api/customer-orders', 'POST', data),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Force refresh of the query with store context
|
// Force refresh of the query with store context
|
||||||
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString().includes('/api/customer-orders') });
|
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString()?.includes('/api/customer-orders') ?? false });
|
||||||
queryClient.refetchQueries({ predicate: (query) => query.queryKey[0]?.toString().includes('/api/customer-orders') });
|
queryClient.refetchQueries({ predicate: (query) => query.queryKey[0]?.toString()?.includes('/api/customer-orders') ?? false });
|
||||||
setShowCreateModal(false);
|
setShowCreateModal(false);
|
||||||
toast({
|
toast({
|
||||||
title: "Succès",
|
title: "Succès",
|
||||||
@@ -100,7 +102,7 @@ export default function CustomerOrders() {
|
|||||||
mutationFn: ({ id, data }: { id: number; data: any }) =>
|
mutationFn: ({ id, data }: { id: number; data: any }) =>
|
||||||
apiRequest(`/api/customer-orders/${id}`, 'PUT', data),
|
apiRequest(`/api/customer-orders/${id}`, 'PUT', data),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString().includes('/api/customer-orders') });
|
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString()?.includes('/api/customer-orders') ?? false });
|
||||||
setShowEditModal(false);
|
setShowEditModal(false);
|
||||||
setSelectedOrder(null);
|
setSelectedOrder(null);
|
||||||
toast({
|
toast({
|
||||||
@@ -121,7 +123,7 @@ export default function CustomerOrders() {
|
|||||||
const deleteMutation = useMutation({
|
const deleteMutation = useMutation({
|
||||||
mutationFn: (id: number) => apiRequest(`/api/customer-orders/${id}`, 'DELETE'),
|
mutationFn: (id: number) => apiRequest(`/api/customer-orders/${id}`, 'DELETE'),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString().includes('/api/customer-orders') });
|
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString()?.includes('/api/customer-orders') ?? false });
|
||||||
setShowDeleteModal(false);
|
setShowDeleteModal(false);
|
||||||
setSelectedOrder(null);
|
setSelectedOrder(null);
|
||||||
toast({
|
toast({
|
||||||
@@ -143,7 +145,7 @@ export default function CustomerOrders() {
|
|||||||
mutationFn: ({ id, status }: { id: number; status: string }) =>
|
mutationFn: ({ id, status }: { id: number; status: string }) =>
|
||||||
apiRequest(`/api/customer-orders/${id}`, 'PUT', { status }),
|
apiRequest(`/api/customer-orders/${id}`, 'PUT', { status }),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString().includes('/api/customer-orders') });
|
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString()?.includes('/api/customer-orders') ?? false });
|
||||||
toast({
|
toast({
|
||||||
title: "Succès",
|
title: "Succès",
|
||||||
description: "Statut de la commande mis à jour",
|
description: "Statut de la commande mis à jour",
|
||||||
@@ -156,7 +158,7 @@ export default function CustomerOrders() {
|
|||||||
mutationFn: ({ id, customerNotified }: { id: number; customerNotified: boolean }) =>
|
mutationFn: ({ id, customerNotified }: { id: number; customerNotified: boolean }) =>
|
||||||
apiRequest(`/api/customer-orders/${id}`, 'PUT', { customerNotified }),
|
apiRequest(`/api/customer-orders/${id}`, 'PUT', { customerNotified }),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString().includes('/api/customer-orders') });
|
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0]?.toString()?.includes('/api/customer-orders') ?? false });
|
||||||
toast({
|
toast({
|
||||||
title: "Succès",
|
title: "Succès",
|
||||||
description: "Statut de notification mis à jour",
|
description: "Statut de notification mis à jour",
|
||||||
@@ -685,10 +687,12 @@ export default function CustomerOrders() {
|
|||||||
Gestion des commandes clients et étiquettes
|
Gestion des commandes clients et étiquettes
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={() => setShowCreateModal(true)} className="bg-blue-600 hover:bg-blue-700 text-white shadow-md">
|
{permissions.canCreate('customer-orders') && (
|
||||||
<Plus className="w-4 h-4 mr-2" />
|
<Button onClick={() => setShowCreateModal(true)} className="bg-blue-600 hover:bg-blue-700 text-white shadow-md">
|
||||||
Nouvelle Commande
|
<Plus className="w-4 h-4 mr-2" />
|
||||||
</Button>
|
Nouvelle Commande
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -847,7 +851,7 @@ export default function CustomerOrders() {
|
|||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{user?.role === 'admin' && (
|
{permissions.canDelete('customer-orders') && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
Reference in new issue
Block a user