diff --git a/app/(prizes)/prizes/[user_id]/page.tsx b/app/(prizes)/prizes/[user_id]/page.tsx index 4a0b067..58b4c80 100644 --- a/app/(prizes)/prizes/[user_id]/page.tsx +++ b/app/(prizes)/prizes/[user_id]/page.tsx @@ -20,13 +20,12 @@ const PrizesPage = ({ params }: { params: { user_id: string } }) => { // Fetching data using TanStack Query const { data, isLoading, error } = useQuery( - [`gifts-${params.user_id}`, params.user_id, selectedPrize], // Query key using user_id + [`gifts-${params.user_id}`, params.user_id], // Query key using user_id () => axios .get(`https://sms.turkmentv.gov.tm/api/gifts/${params.user_id}`) .then((response) => response.data), { - staleTime: 60000, // Cache data for 1 minute // Handle error with onError callback to trigger the redirect onError: () => { router.push('/prizes/auth'); diff --git a/components/MobileMenu.tsx b/components/MobileMenu.tsx index f842cf8..203befc 100644 --- a/components/MobileMenu.tsx +++ b/components/MobileMenu.tsx @@ -153,6 +153,7 @@ const MobileMenu = () => { { setDropDownOpened(false); onClickCloseBurgerHandler(); @@ -168,6 +169,16 @@ const MobileMenu = () => { }}> TV market + { + setDropDownOpened(false); + onClickCloseBurgerHandler(); + }}> + Sowgatlar + diff --git a/components/Nav.tsx b/components/Nav.tsx index e41552b..2287086 100644 --- a/components/Nav.tsx +++ b/components/Nav.tsx @@ -107,7 +107,7 @@ const Nav = () => {
{ setDropDownOpened(false)}> SMS ulgamy + setDropDownOpened(false)}> + Sowgatlar +
diff --git a/components/prizes/PrizeCard.tsx b/components/prizes/PrizeCard.tsx index 149f80b..0f093ad 100644 --- a/components/prizes/PrizeCard.tsx +++ b/components/prizes/PrizeCard.tsx @@ -36,7 +36,9 @@ const PrizeCard = ({ className, }: IProps) => { const [dialogOpen, setDialogOpen] = useState(false); - const [dialogTitle, setDialogTitle] = useState('Успешно'); + const [dialogTitle, setDialogTitle] = useState('Выберите приз'); + const [dialogDescription, setDialogDescription] = useState('Загрузка...'); + const [isSuccess, setIsSuccess] = useState(false); // TanStack Query mutation for the API request const choosePrizeMutation = useMutation({ @@ -45,22 +47,36 @@ const PrizeCard = ({ code, }), onSuccess: () => { - // Set the selected prize on successful API request - setSelectedPrize(id); setDialogTitle('Успешно'); - setDialogOpen(true); // Open the dialog on success + setDialogDescription('Приз успешно выбран.'); + setIsSuccess(true); // Mark as success so we can handle setting the prize when dialog closes }, onError: () => { - // Set the dialog title to "Ошибка" on error setDialogTitle('Ошибка'); - setDialogOpen(true); // Open the dialog on error + setDialogDescription('Произошла ошибка, попробуйте еще раз.'); + setIsSuccess(false); // Reset on error }, }); - const handleDialogTriggerClick = () => { + const handleDialogOpen = () => { + // Reset the dialog to show the loading state + setDialogTitle('Загрузка...'); + setDialogDescription('Пожалуйста подождите'); + setIsSuccess(false); // Reset success state before opening + + // Trigger the mutation when the dialog opens choosePrizeMutation.mutate(); }; + const handleDialogClose = (open: boolean) => { + setDialogOpen(open); + + // Check if the dialog was closed and if the mutation was successful + if (!open && isSuccess) { + setSelectedPrize(id); // Set the selected prize when the dialog closes after success + } + }; + return (
{description}

+ {variant === 'default' ? ( - - - {choosePrizeMutation.isLoading ? 'Loading...' : 'Выбрать'} - - - - {dialogTitle} - Все прошло успешно! - - - - - - - - + + + {/* DialogContent that shows loading or response */} + + + {dialogTitle} + {dialogDescription} + + {dialogTitle !== 'Загрузка...' && ( + + + + + + )} + + +
+ ) : variant === 'disabled' ? (