import { useEffect, useState } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { t } from "@/utils"; import { getItemBuyerListApi } from "@/utils/api"; import NoDataFound from "../../../public/assets/no_data_found_illustrator.svg"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Checkbox } from "@/components/ui/checkbox"; import { Skeleton } from "@/components/ui/skeleton"; import CustomImage from "@/components/Common/CustomImage"; const SoldOutModal = ({ productDetails, showSoldOut, setShowSoldOut, selectedRadioValue, setSelectedRadioValue, setShowConfirmModal, }) => { const [buyers, setBuyers] = useState([]); const [isNoneOfAboveChecked, setIsNoneOfAboveChecked] = useState(false); const [isLoading, setIsLoading] = useState(false); const isJobAd = productDetails?.category?.is_job_category === 1; useEffect(() => { if (showSoldOut) { getBuyers(); } }, [showSoldOut]); const handleNoneOfAboveChecked = (checked) => { if (selectedRadioValue !== null) { setSelectedRadioValue(null); } setIsNoneOfAboveChecked(checked); }; const handleRadioButtonCheck = (value) => { if (isNoneOfAboveChecked) { setIsNoneOfAboveChecked(false); } setSelectedRadioValue(value); }; const handleHideModal = () => { setIsNoneOfAboveChecked(false); setSelectedRadioValue(null); setShowSoldOut(false); }; const getBuyers = async () => { try { setIsLoading(true); const res = await getItemBuyerListApi.getItemBuyerList({ item_id: productDetails?.id, }); setBuyers(res?.data?.data); } catch (error) { console.log(error); } finally { setIsLoading(false); } }; const handleSoldOut = () => { setShowSoldOut(false); setShowConfirmModal(true); }; return ( { e.preventDefault(); }} > {isJobAd ? t("whoWasHired") : t("whoMadePurchase")}

{productDetails?.name}

{productDetails?.formatted_price}

{isJobAd ? t("selectHiredApplicant") : t("selectBuyerFromList")}
{isLoading ? ( // Buyers list skeleton <> {[1, 2, 3].map((item) => (
))} ) : ( <> {buyers?.length > 0 ? ( buyers?.map((buyer) => { return (
{buyer?.name}
handleRadioButtonCheck(value)} value={selectedRadioValue} >
); }) ) : (

{isJobAd ? t("noApplicantsFound") : t("noBuyersFound")}

)} )}
handleNoneOfAboveChecked(checked)} />
); }; export default SoldOutModal;