@@ -1,63 +1,69 @@
|
||||
import { useState, type FC } from 'react'
|
||||
import Button from '@/components/Button'
|
||||
import DefaulModal from '@/components/DefaulModal'
|
||||
import Input from '@/components/Input'
|
||||
import { toast } from '@/components/Toast'
|
||||
import { usePurchaseInitate } from '@/pages/catalogue/hooks/useCatalogueData'
|
||||
import { extractErrorMessage } from '@/helpers/utils'
|
||||
import Button from "@/components/Button";
|
||||
import DefaulModal from "@/components/DefaulModal";
|
||||
import Input from "@/components/Input";
|
||||
import { toast } from "@/components/Toast";
|
||||
import { extractErrorMessage } from "@/helpers/utils";
|
||||
import { usePurchaseInitate } from "@/pages/catalogue/hooks/useCatalogueData";
|
||||
import { useState, type FC } from "react";
|
||||
|
||||
const BuyCatalog: FC = () => {
|
||||
const [showModal, setShowModal] = useState<boolean>(false);
|
||||
const [count, setCount] = useState<number>(0);
|
||||
const { mutate, isPending } = usePurchaseInitate();
|
||||
|
||||
const [showModal, setShowModal] = useState<boolean>(false)
|
||||
const [count, setCount] = useState<number>(0)
|
||||
const { mutate, isPending } = usePurchaseInitate()
|
||||
|
||||
const handlePurchaseInitate = () => {
|
||||
if (count > 0) {
|
||||
mutate({ count: count }, {
|
||||
onSuccess: (data) => {
|
||||
console.log(data);
|
||||
// TODO منتقل بشه به صفحه صورت حساب
|
||||
},
|
||||
onError: (error) => {
|
||||
toast(extractErrorMessage(error), 'error')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
toast('تعداد را انتخاب کنید')
|
||||
}
|
||||
const handlePurchaseInitate = () => {
|
||||
if (count > 0) {
|
||||
mutate(
|
||||
{ count: count },
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
console.log(data);
|
||||
// TODO منتقل بشه به صفحه صورت حساب
|
||||
},
|
||||
onError: (error) => {
|
||||
toast(extractErrorMessage(error), "error");
|
||||
},
|
||||
},
|
||||
);
|
||||
} else {
|
||||
toast("تعداد را انتخاب کنید");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='px-4'>
|
||||
<div className='flex justify-center'>
|
||||
<Button onClick={() => setShowModal(true)} className='w-fit px-5'>
|
||||
خرید کاتالو
|
||||
</Button>
|
||||
</div>
|
||||
return (
|
||||
<div className="px-4">
|
||||
<div className="flex justify-center">
|
||||
<Button onClick={() => setShowModal(true)} className="w-fit px-5">
|
||||
خرید کاتالوگ
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<DefaulModal
|
||||
open={showModal}
|
||||
close={() => setShowModal(false)}
|
||||
isHeader
|
||||
title_header='خرید کاتالوگ'
|
||||
>
|
||||
<div className='mt-4'>
|
||||
<Input
|
||||
label='تعداد'
|
||||
type='number'
|
||||
value={count}
|
||||
onChange={(e) => setCount(+e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-6 flex justify-end'>
|
||||
<Button disabled={isPending} onClick={handlePurchaseInitate} className='w-fit px-5'>
|
||||
صدور صورتحساب
|
||||
</Button>
|
||||
</div>
|
||||
</DefaulModal>
|
||||
<DefaulModal
|
||||
open={showModal}
|
||||
close={() => setShowModal(false)}
|
||||
isHeader
|
||||
title_header="خرید کاتالوگ"
|
||||
>
|
||||
<div className="mt-4">
|
||||
<Input
|
||||
label="تعداد"
|
||||
type="number"
|
||||
value={count}
|
||||
onChange={(e) => setCount(+e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
<div className="mt-6 flex justify-end">
|
||||
<Button
|
||||
disabled={isPending}
|
||||
onClick={handlePurchaseInitate}
|
||||
className="w-fit px-5"
|
||||
>
|
||||
صدور صورتحساب
|
||||
</Button>
|
||||
</div>
|
||||
</DefaulModal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default BuyCatalog
|
||||
export default BuyCatalog;
|
||||
|
||||
Reference in New Issue
Block a user