diff --git a/app/(main)/lottery/auth/page.tsx b/app/(main)/cekilis/auth/page.tsx similarity index 100% rename from app/(main)/lottery/auth/page.tsx rename to app/(main)/cekilis/auth/page.tsx diff --git a/app/(main)/lottery/page.tsx b/app/(main)/cekilis/page.tsx similarity index 100% rename from app/(main)/lottery/page.tsx rename to app/(main)/cekilis/page.tsx diff --git a/components/MobileMenu.tsx b/components/MobileMenu.tsx index d42e911..f1f76bb 100644 --- a/components/MobileMenu.tsx +++ b/components/MobileMenu.tsx @@ -178,9 +178,9 @@ const MobileMenu = () => { Sowgatlar { setDropDownOpened(false); onClickCloseBurgerHandler(); diff --git a/components/Nav.tsx b/components/Nav.tsx index 5aae4b3..8946516 100644 --- a/components/Nav.tsx +++ b/components/Nav.tsx @@ -2,8 +2,6 @@ import Image from 'next/image'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; -import { AiOutlineUser } from 'react-icons/ai'; -import ThemeSwitch from './home/ThemeSwitch'; import { useContext, useEffect, useRef, useState } from 'react'; import GlobalContext from '@/context/GlobalContext'; import burger from '@/public/menu-outline.svg'; @@ -140,9 +138,9 @@ const Nav = () => { Sowgatlar setDropDownOpened(false)}> Bije diff --git a/components/common/Confetti.tsx b/components/common/Confetti.tsx index 52d4f06..c26e4f9 100644 --- a/components/common/Confetti.tsx +++ b/components/common/Confetti.tsx @@ -19,7 +19,7 @@ const Confetti = () => { const mobile = useMediaQuery("(max-width: 426px)"); useEffect(() => { - setTimeout(() => setRecycle(false), 30000); + setTimeout(() => setRecycle(false), 10000); }, [recycle]); return ( diff --git a/components/lottery/LotteryMain.tsx b/components/lottery/LotteryMain.tsx index 6998a72..094cd26 100644 --- a/components/lottery/LotteryMain.tsx +++ b/components/lottery/LotteryMain.tsx @@ -1,29 +1,46 @@ +"use client"; import LotteryHeader from "@/components/lottery/LotteryHeader"; import LotteryRulesSection from "@/components/lottery/rules/LotteryRulesSection"; import LotteryCountDown from "@/components/lottery/countDown/LotteryCountDown"; import Link from "next/link"; import { authenticateLottery } from "@/api"; import { redirect } from "next/navigation"; -import { cookies } from "next/headers"; import { getLotteryStatus } from "@/lib/actions"; import LotteryWinners from "./LotteryWinners"; +import { useEffect, useState } from "react"; +import { ILotteryResponse } from "@/models/lottery/lottery.model"; -async function getData() { - const cookieStore = await cookies(); - const phone = cookieStore.get("phoneNumber"); - const key = cookieStore.get("key"); - if (phone?.value && key?.value) { - const res = await authenticateLottery(phone.value, key.value); - return res; - } else { - redirect("/lottery/auth"); - } -} +const LotteryMain = () => { + const [lotteryData, setLotteryData] = useState(); -const LotteryMain = async () => { - const lotteryData = await getData(); + useEffect(() => { + async function getData() { + const phone = document.cookie + .split("; ") + [ + document.cookie + .split("; ") + .findIndex((item) => item.startsWith("phoneNumber=")) + ].split("=")[1]; + const key = document.cookie + .split("; ") + [ + document.cookie + .split("; ") + .findIndex((item) => item.startsWith("key=")) + ].split("=")[1]; + if (phone && key) { + const res = await authenticateLottery(phone, key); + setLotteryData(res); + } else { + redirect("/cekilis/auth"); + } + } - const status = await getLotteryStatus( + getData(); + }, []); + + const status = getLotteryStatus( lotteryData?.data.start_time, lotteryData?.data.end_time ); @@ -33,41 +50,43 @@ const LotteryMain = async () => {

{lotteryData.errorMessage}

) : ( -
-
- + lotteryData?.data && ( +
+
+ - {status === "Upcoming" && ( -
- -
- )} -
- -
- -
-
- - Çykmak - + {status === "Upcoming" && ( +
+ +
+ )} +
+ +
+ +
+
+ + Çykmak + +
-
+ ) ); }; diff --git a/components/lottery/LotteryWinnersSection.tsx b/components/lottery/LotteryWinnersSection.tsx index c033831..bb6aebe 100644 --- a/components/lottery/LotteryWinnersSection.tsx +++ b/components/lottery/LotteryWinnersSection.tsx @@ -1,5 +1,4 @@ import { useState, useEffect } from "react"; -import { useLotteryAuth } from "@/store/useLotteryAuth"; import { LotteryWinnerDataSimplified } from "@/typings/lottery/lottery.types"; import LotteryWinnersList from "./winners/LotteryWinnersList"; import LotterySlotCounter from "./slotCounter/LotterySlotCounter"; diff --git a/components/lottery/auth/LotteryAuthForm.tsx b/components/lottery/auth/LotteryAuthForm.tsx index b2c5894..f8291be 100644 --- a/components/lottery/auth/LotteryAuthForm.tsx +++ b/components/lottery/auth/LotteryAuthForm.tsx @@ -36,10 +36,9 @@ const LotteryAuthForm = () => { if (response.errorMessage) { setError(response.errorMessage); } else { - console.log(response); - document.cookie = `phoneNumber=${phoneNumber};path=/`; - document.cookie = `key=${key};path=/`; - router.replace("/lottery"); + document.cookie = `phoneNumber=${phoneNumber};path=/;max-age=3600;`; + document.cookie = `key=${key};path=/;max-age=3600;`; + router.replace("/cekilis"); } } catch (err) { setError("Telefon belgisi ýa-da açar nädogry"); diff --git a/components/lottery/countDown/LotteryCountDown.tsx b/components/lottery/countDown/LotteryCountDown.tsx index 76ca6b3..3f4859a 100644 --- a/components/lottery/countDown/LotteryCountDown.tsx +++ b/components/lottery/countDown/LotteryCountDown.tsx @@ -57,10 +57,10 @@ const LotteryCountDown: React.FC = ({

{status === "Ongoing" - ? "Bije dowam edýär" + ? "Çeklis dowam edýär" : status === "Finished" - ? "Bije tamamlandy" - : "Bije"} + ? "Çeklisx tamamlandy" + : null}

{/* LotteryCountDown */} {status === "Upcoming" && ( @@ -69,9 +69,6 @@ const LotteryCountDown: React.FC = ({

{timeLeft.hours}

-

- sagat -

{/* Dots */} @@ -84,9 +81,6 @@ const LotteryCountDown: React.FC = ({

{timeLeft.minutes}

-

- minut -

{/* Dots */} @@ -99,22 +93,9 @@ const LotteryCountDown: React.FC = ({

{timeLeft.seconds}

-

- sekunt -

)} - -
- - {status === "Upcoming" - ? "- den başlar" - : status === "Ongoing" - ? "girmek üçin aşakda kodyňyzy giriziň" - : "netijeleri görmek üçin aşakda kodyňyzy giriziň"} - -
); }; diff --git a/components/lottery/rules/LotteryRulesSection.tsx b/components/lottery/rules/LotteryRulesSection.tsx index 6072749..2694204 100644 --- a/components/lottery/rules/LotteryRulesSection.tsx +++ b/components/lottery/rules/LotteryRulesSection.tsx @@ -19,11 +19,6 @@ const LotteryRulesSection = ({ show = true, data }: IProps) => { data ? data?.data?.bije_count : 0 ); - if (!data.errorMessage) { - document.cookie = "phoneNumber=;path=/"; - document.cookie = "key=;path=/"; - } - // Subscribe to WebSocket messages useEffect(() => { const unsubscribe = subscribeToMessages((event) => { @@ -77,9 +72,9 @@ const LotteryRulesSection = ({ show = true, data }: IProps) => { -
+

- Umumy gatnaşyjylaryň sany: + Gatnaşyjylaryň sany:

{totalParticipants}

diff --git a/components/lottery/winners/LotteryWinner.tsx b/components/lottery/winners/LotteryWinner.tsx index fdfc88c..f63e5a7 100644 --- a/components/lottery/winners/LotteryWinner.tsx +++ b/components/lottery/winners/LotteryWinner.tsx @@ -1,6 +1,6 @@ -'use client'; +"use client"; -import { motion } from 'framer-motion'; +import { motion } from "framer-motion"; interface IProps { phone: string; @@ -14,14 +14,14 @@ const LotteryWinner = ({ phone, ticket, isNew, winnerNumber }: IProps) => { + className="flex flex-col gap-2 md:pb-4 pb-3 border-b w-full border-[#CECCFF]" + >

{/* The winner of the {winnerNumber} stage: */} {winnerNumber} - {' - nji ýeňiji'} + {" - nji ýeňiji"}

{phone}

diff --git a/lib/actions.ts b/lib/actions.ts index de9d78f..63629a2 100644 --- a/lib/actions.ts +++ b/lib/actions.ts @@ -1,6 +1,4 @@ -"use server"; - -export async function getLotteryStatus(startTime: string, endTime: string) { +export function getLotteryStatus(startTime: string, endTime: string) { const now = new Date(); const start = new Date(startTime); const end = new Date(endTime); diff --git a/package.json b/package.json index 22f7e78..6f92a42 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev --turbopack -p 4000", + "dev": "next dev -p 4000", "build": "next build", "start": "next start", "lint": "next lint"