diff --git a/src/pages/receipts/Create.tsx b/src/pages/receipts/Create.tsx index aa3b629..9277891 100644 --- a/src/pages/receipts/Create.tsx +++ b/src/pages/receipts/Create.tsx @@ -8,8 +8,6 @@ import { CreateReceiptType, ReceiptCreateItemsType } from './types/ReceiptTypes' import { useFormik } from 'formik' import * as Yup from 'yup' import { toast } from 'react-toastify' -import { useGetCustomers } from '../customer/hooks/useCustomerData' -import { CustomerItemType } from '../customer/types/CustomerTypes' import PageLoading from '../../components/PageLoading' import { useCreateInvoice } from './hooks/useReceiptData' import { useNavigate } from 'react-router-dom' @@ -17,16 +15,19 @@ import { Pages } from '../../config/Pages' import { ErrorType } from '../../helpers/types' import { RecurringPeriodEnum } from './enum/ReceipEnum' import SwitchComponent from '../../components/Switch' +import { useGetCompanies } from '../company/hooks/useCompanyData' +import { CompanyItemType } from '../company/types/CompanyTypes' +import moment from 'moment-jalaali' const CreateReceipt: FC = () => { const navigate = useNavigate() const { t } = useTranslation('global') const [items, setItems] = useState([]) - const [customer, setCustomer] = useState() + const [customer, setCustomer] = useState() const [isRecurring, setIsRecurring] = useState(false) const [type, setType] = useState(RecurringPeriodEnum.WEEKLY) const [maxRecurringCycles, setMaxRecurringCycles] = useState(0) - const getCustomers = useGetCustomers(1, true) + const getCustomers = useGetCompanies(1) const createInvoice = useCreateInvoice() const formik = useFormik({ @@ -54,14 +55,14 @@ const CreateReceipt: FC = () => { const handleChangeCustomer = (e: ChangeEvent) => { const value = e.target.value - const customer = getCustomers.data?.data?.customers?.find((item: CustomerItemType) => item.id === value) + const customer = getCustomers.data?.data?.companies?.find((item: CompanyItemType) => item.id === value) setCustomer(customer) } const handleSubmit = () => { if (customer) { const params: CreateReceiptType = { - userId: customer?.id, + companyId: customer?.id, items: items, isRecurring: isRecurring, recurringPeriod: isRecurring ? +type : undefined, @@ -114,18 +115,18 @@ const CreateReceipt: FC = () => {
-
+ {/*
{t('receip.customer_information')} -
+
*/}
{ + items={getInvoices.data?.data?.companies?.map((item: CompanyItemType) => { return { - label: item.firstname + ' ' + item.lastname, + label: item.name, value: item.id } })} @@ -146,7 +147,7 @@ const ReceiptsList: FC = () => { return ( - + @@ -155,16 +156,12 @@ const ReceiptsList: FC = () => { - {item.isRecurring ? t(`receip.${item.recurringPeriod}`) : '_'} + {item.isRecurring ? t('receip.recurringPeriod') : '_'} {item.maxRecurringCycles} - - - - - + ) }) diff --git a/src/pages/receipts/hooks/useReceiptData.ts b/src/pages/receipts/hooks/useReceiptData.ts index ed5da18..f146a1d 100644 --- a/src/pages/receipts/hooks/useReceiptData.ts +++ b/src/pages/receipts/hooks/useReceiptData.ts @@ -7,13 +7,11 @@ export const useGetInvoices = ( customerId: string, search: string, date: string, - endDate: string, - page: number + endDate: string ) => { return useQuery({ - queryKey: ["invoices", status, customerId, search, date, endDate, page], - queryFn: () => - api.getInvoces(status, customerId, search, date, endDate, page), + queryKey: ["invoices", status, customerId, search, date, endDate], + queryFn: () => api.getInvoces(status, customerId, search, date, endDate), }); }; @@ -22,17 +20,3 @@ export const useCreateInvoice = () => { mutationFn: (variables: CreateReceiptType) => api.createInvoice(variables), }); }; - -export const useGetInvoiceById = (id: string) => { - return useQuery({ - queryKey: ["invoice", id], - queryFn: () => api.getInvoiceById(id), - }); -}; - -export const useUpdateInvoice = () => { - return useMutation({ - mutationFn: ({ id, params }: { id: string; params: CreateReceiptType }) => - api.updateInvoice(id, params), - }); -}; diff --git a/src/pages/receipts/service/ReceiptService.ts b/src/pages/receipts/service/ReceiptService.ts index f2aff6a..981d524 100644 --- a/src/pages/receipts/service/ReceiptService.ts +++ b/src/pages/receipts/service/ReceiptService.ts @@ -6,16 +6,14 @@ export const getInvoces = async ( customerId: string, search: string, date: string, - endDate: string, - page: number + endDate: string ) => { const params = new URLSearchParams(); if (status) params.append("status", status); - if (customerId) params.append("userId", customerId); + if (customerId) params.append("companyId", customerId); if (search) params.append("q", search); if (date) params.append("since", date); if (endDate) params.append("to", endDate); - if (page) params.append("page", page.toString()); const query = params.toString(); const { data } = await axios.get(`/invoices?${query}`); return data; @@ -25,13 +23,3 @@ export const createInvoice = async (params: CreateReceiptType) => { const { data } = await axios.post(`/invoices`, params); return data; }; - -export const getInvoiceById = async (id: string) => { - const { data } = await axios.get(`/invoices/${id}`); - return data; -}; - -export const updateInvoice = async (id: string, params: CreateReceiptType) => { - const { data } = await axios.patch(`/invoices/${id}`, params); - return data; -}; diff --git a/src/pages/receipts/types/ReceiptTypes.ts b/src/pages/receipts/types/ReceiptTypes.ts index 0cab68c..16acacf 100644 --- a/src/pages/receipts/types/ReceiptTypes.ts +++ b/src/pages/receipts/types/ReceiptTypes.ts @@ -1,5 +1,5 @@ export type CreateReceiptType = { - userId: string; + companyId: string; items: ReceiptCreateItemsType[]; isRecurring: boolean; recurringPeriod: number | undefined; @@ -24,9 +24,9 @@ export type ReceiptItemType = { totalPrice: number; subscriptionPlan?: string | null; items: ReceiptItemType[]; - user: { - firstName: string; - lastName: string; + lateFee: number; + company: { + name: string; }; dueDate: string; status: "PENDING" | "PAID" | "CANCELLED" | "EXPIRED" | "APPROVED"; @@ -34,7 +34,6 @@ export type ReceiptItemType = { isRecurring: boolean; recurringPeriod?: number; maxRecurringCycles?: number; - lateFee: number; }; export type InvoiceUserItemType = {