diff --git a/src/App.jsx b/src/App.jsx index af5cbe5..f45eae0 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -11,7 +11,7 @@ import Currency from './pages/Currency'; import Employees from './pages/Employees'; import Login from './pages/Login'; import Payments from './pages/Payments'; -import Permissions from './pages/Permissions'; // Yangi sahifa +import Permissions from './pages/Permissions'; import Reference from './pages/Reference'; import Warhouses from './pages/Warhouses'; diff --git a/src/components/Searchs.tsx b/src/components/Searchs.tsx index e73a5ab..6509a73 100644 --- a/src/components/Searchs.tsx +++ b/src/components/Searchs.tsx @@ -1,13 +1,29 @@ import { Search } from 'lucide-react'; +import { Dispatch, SetStateAction } from 'react'; -const Searchs = ({ searchTerm, loading, setSearchTerm, placeholder = 'Ism, telefon yoki manzil bo‘yicha qidirish...' }) => { +interface Props { + searchTerm: string; + loading: boolean; + setSearchTerm: Dispatch>; + placeholder: string; +} + +const Searchs = ({ searchTerm, loading, setSearchTerm, placeholder = 'Qidirish' }: Props) => { return (
- setSearchTerm(e.target.value)} className="w-full border border-slate-300 rounded-lg pl-10 pr-4 py-2 focus:outline-none focus:ring-2 focus:ring-[#3489e3]" disabled={loading} /> + setSearchTerm(e.target.value)} + className="w-full border border-slate-300 rounded-lg pl-10 pr-4 py-2 focus:outline-none focus:ring-2 focus:ring-[#3489e3]" + disabled={loading} + />
diff --git a/src/components/clients/ClientList.tsx b/src/components/clients/ClientList.jsx similarity index 70% rename from src/components/clients/ClientList.tsx rename to src/components/clients/ClientList.jsx index 7dc11d5..7171d7d 100644 --- a/src/components/clients/ClientList.tsx +++ b/src/components/clients/ClientList.jsx @@ -2,8 +2,8 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { Edit, Trash2, Users } from 'lucide-react'; import { useEffect, useState } from 'react'; import axiosInstance from '../../api/axiosInstance'; -import Searchs from '../../components/Searchs'; import Pagination from '../Pagination'; +import Searchs from '../Searchs'; const ClientList = ({ alert, setAlert, setClients, setCargoId }) => { const client = useQueryClient(); @@ -24,7 +24,7 @@ const ClientList = ({ alert, setAlert, setClients, setCargoId }) => { axiosInstance.get('/clients/list', { params: { page: currentPage, - sort: 'id', + sort: 'active', clientName: searchTerm, direction: 'desc', }, @@ -44,7 +44,7 @@ const ClientList = ({ alert, setAlert, setClients, setCargoId }) => { }; const { mutate: deleteClient, isPending: deleteLoad } = useMutation({ - mutationFn: (id: number) => axiosInstance.delete(`/users/delete/${id}`), + mutationFn: (id) => axiosInstance.delete(`/users/delete/${id}`), mutationKey: ['clientsDelete'], onSuccess: () => { client.invalidateQueries({ queryKey: ['clients'] }); @@ -57,7 +57,7 @@ const ClientList = ({ alert, setAlert, setClients, setCargoId }) => { }, }); - const handlePageChange = (page: number) => { + const handlePageChange = (page) => { setCurrentPage(page); }; @@ -81,7 +81,10 @@ const ClientList = ({ alert, setAlert, setClients, setCargoId }) => { Passport seriyasi PNFL Tug'ilgan sana - {(userRole === 'ADMIN' || userRole === 'SUPER_ADMIN') && Amallar} + Holati + {(userRole === 'ADMIN' || userRole === 'SUPER_ADMIN') && ( + Amallar + )} @@ -95,14 +98,32 @@ const ClientList = ({ alert, setAlert, setClients, setCargoId }) => { {client.passportSeries} {client.pinfl} {client.dateOfBirth} + {/* */} {(userRole === 'ADMIN' || userRole === 'SUPER_ADMIN') && (
- - @@ -116,7 +137,13 @@ const ClientList = ({ alert, setAlert, setClients, setCargoId }) => {
- +
); diff --git a/src/components/clients/CreateClient.tsx b/src/components/clients/CreateClient.tsx index e878304..d305621 100644 --- a/src/components/clients/CreateClient.tsx +++ b/src/components/clients/CreateClient.tsx @@ -80,7 +80,7 @@ const CreateClient = ({ clients, setAlert, cargoId }: CreateClientProps) => { const { data: client, refetch: clientRef } = useQuery({ queryKey: ['client_one'], queryFn: async () => axiosInstance.get('/clients/list', { params: { cargoId } }), - select: (data) => data.data.data as { data: any[] }, + select: (data) => data.data.data, }); const { data, refetch } = useQuery({ @@ -102,23 +102,24 @@ const CreateClient = ({ clients, setAlert, cargoId }: CreateClientProps) => { phone: c.phone, pinfl: c.pinfl, }); + setActive(c.active); } clientRef(); refetch(); }, [cargoId, client, refetch, clientRef]); - // useEffect(() => { - // if (currentPassport) { - // setFormData((prev) => ({ - // ...prev, - // fullName: currentPassport.fullName || '', - // passportSeries: currentPassport.passportSeries || '', - // pinfl: currentPassport.passportPin || '', - // dateOfBirth: formatDate(currentPassport.birthDate), - // })); - // setActive(currentPassport.active); - // } - // }, [currentPassport]); + useEffect(() => { + if (currentPassport) { + setFormData((prev) => ({ + ...prev, + fullName: currentPassport.fullName || '', + passportSeries: currentPassport.passportSeries || '', + pinfl: currentPassport.passportPin || '', + dateOfBirth: formatDate(currentPassport.birthDate), + })); + setActive(currentPassport.active); + } + }, [currentPassport]); const { mutate: createMutate } = useMutation({ mutationFn: async (params: any) => { @@ -202,6 +203,8 @@ const CreateClient = ({ clients, setAlert, cargoId }: CreateClientProps) => { setAlert({ type: 'success', message: "Passport ma'lumotlari yangilandi." }); }; + console.log(active); + return (
{(userRole === 'ADMIN' || userRole === 'SUPER_ADMIN') && ( @@ -211,7 +214,15 @@ const CreateClient = ({ clients, setAlert, cargoId }: CreateClientProps) => { {clients ? 'Mijozni tahrirlash' : "Yangi mijoz qo'shish"} - {clients && data && data.length > 0 && } + {clients && data && data.length > 0 && ( + + )}
@@ -225,13 +236,24 @@ const CreateClient = ({ clients, setAlert, cargoId }: CreateClientProps) => { ].map((field) => (
- +
))} {clients && currentPassport && ( @@ -239,22 +261,42 @@ const CreateClient = ({ clients, setAlert, cargoId }: CreateClientProps) => {
- -
)} - {tagetIamge && opneModal && } + {tagetIamge && opneModal && ( + + )} ); }; -const ModalIamge = ({ image, setTargetImage, setOpenModal }: { image: string; setTargetImage: (img: string | null) => void; setOpenModal: (open: boolean) => void }) => { +const ModalIamge = ({ + image, + setTargetImage, + setOpenModal, +}: { + image: string; + setTargetImage: (img: string | null) => void; + setOpenModal: (open: boolean) => void; +}) => { return (
@@ -90,7 +105,10 @@ const ModalPayment = ({ isOpen, onClose, packetId }) => {

Ma'lumotlarni yuklashda xatolik yuz berdi

-
@@ -125,7 +143,14 @@ const ModalPayment = ({ isOpen, onClose, packetId }) => {
To'lov holati: - @@ -162,11 +187,21 @@ const ModalPayment = ({ isOpen, onClose, packetId }) => {
@@ -183,16 +218,21 @@ const ModalPayment = ({ isOpen, onClose, packetId }) => { {data.clickTransactions.map((transaction, index) => (
- ID: {transaction.transactionId} - - {getStatusIcon(transaction.status)} + + ID: {transaction.transactionId} + + {transaction.status}
Summa: -

{formatAmount(transaction.amount)}

+

+ {formatAmount(transaction.amount)} +

Provayder: @@ -204,13 +244,19 @@ const ModalPayment = ({ isOpen, onClose, packetId }) => {
{transaction.completeTime && (
- Tugallangan: -

{formatDate(transaction.completeTime)}

+ + Tugallangan: + +

+ {formatDate(transaction.completeTime)} +

)} {transaction.cancelTime && (
- Bekor qilingan: + + Bekor qilingan: +

{formatDate(transaction.cancelTime)}

)} @@ -239,16 +285,21 @@ const ModalPayment = ({ isOpen, onClose, packetId }) => { {data.paymeTransactions.map((transaction, index) => (
- ID: {transaction.transactionId} - - {getStatusIcon(transaction.status)} + + ID: {transaction.transactionId} + + {transaction.status}
Summa: -

{formatAmount(transaction.amount)}

+

+ {formatAmount(transaction.amount)} +

Provayder: @@ -260,13 +311,19 @@ const ModalPayment = ({ isOpen, onClose, packetId }) => {
{transaction.completeTime && (
- Tugallangan: -

{formatDate(transaction.completeTime)}

+ + Tugallangan: + +

+ {formatDate(transaction.completeTime)} +

)} {transaction.cancelTime && (
- Bekor qilingan: + + Bekor qilingan: +

{formatDate(transaction.cancelTime)}

)} @@ -285,12 +342,16 @@ const ModalPayment = ({ isOpen, onClose, packetId }) => {
)} - {(!data.clickTransactions || data.clickTransactions.length === 0) && (!data.paymeTransactions || data.paymeTransactions.length === 0) && !(['PAYED', 'PENDING'].includes(data.paymentStatus) && data.paymentType === 'CASH') && ( -
- -

Hozircha tranzaksiyalar mavjud emas

-
- )} + {(!data.clickTransactions || data.clickTransactions.length === 0) && + (!data.paymeTransactions || data.paymeTransactions.length === 0) && + !( + ['PAYED', 'PENDING'].includes(data.paymentStatus) && data.paymentType === 'CASH' + ) && ( +
+ +

Hozircha tranzaksiyalar mavjud emas

+
+ )}
) : (
diff --git a/src/components/payments/PaymentStatusSelector.jsx b/src/components/payments/PaymentStatusSelector.jsx index f65e27b..08ed72a 100644 --- a/src/components/payments/PaymentStatusSelector.jsx +++ b/src/components/payments/PaymentStatusSelector.jsx @@ -40,18 +40,14 @@ const PaymentStatusSelector = ({ value, onChange, disabled = false }) => { const [position, setPosition] = useState({ top: 0, left: 0, width: 0 }); const buttonRef = useRef(null); - const currentStatus = paymentStatuses.find((status) => status.value === value) || paymentStatuses[0]; + const currentStatus = + paymentStatuses.find((status) => status.value === value) || paymentStatuses[0]; const CurrentIcon = currentStatus.icon; const handleSelect = (statusValue) => { - if (statusValue === 'PAID' && (value === 'UNPAID' || value === 'PENDING')) { + // Faqat PAYED holatiga o'tkazish + if (statusValue === 'PAYED' && value !== 'PAYED') { onChange('PAYED'); - } else if (statusValue === 'PAID' && value === 'PAID') { - // Already paid, do nothing - return; - } else if (statusValue !== 'PAID') { - // Show warning for non-PAID status changes - return; } setIsOpen(false); }; @@ -88,17 +84,18 @@ const PaymentStatusSelector = ({ value, onChange, disabled = false }) => { {currentStatus.label}
- {!disabled && } + {!disabled && ( + + )} {/* Options (portal) */} {isOpen && createPortal( <> - {/* Backdrop */}
setIsOpen(false)} /> - - {/* Dropdown */}
{ {paymentStatuses.map((status) => { const StatusIcon = status.icon; const isSelected = status.value === value; - const isDisabled = status.value !== 'PAID' || value === 'PAID'; return (
@@ -162,10 +176,20 @@ const PaymentsList = ({ setAlert }) => { {client.cargoId} {client.partyName} {client.packetName} - {client.paymentType === null ? To'lanmagan : {client.paymentType === 'CASH' ? 'Naxt' : client.paymentType}} + {client.paymentType === null ? ( + To'lanmagan + ) : ( + + {client.paymentType === 'CASH' ? 'Naxt' : client.paymentType} + + )} {(userRole === 'ADMIN' || userRole === 'SUPER_ADMIN') && ( - handlePaymentStatusChange(client.packetId, value)} disabled={client.paymentStatus === 'PAYED'} /> + handlePaymentStatusChange(client.packetId, value)} + disabled={client.paymentStatus === 'PAYED'} + /> )} @@ -187,7 +211,13 @@ const PaymentsList = ({ setAlert }) => {
- +
);