From 71ac157288bdc08b9f73ae350475157f110cf8e2 Mon Sep 17 00:00:00 2001 From: PhorDotC Date: Wed, 24 Jul 2024 05:50:10 +0700 Subject: [PATCH 1/6] feat: logic join modal --- src/app/(main)/home/page.tsx | 12 +++++++ src/components/(main)/home/CustomButton.tsx | 22 +++++++++++-- src/components/(main)/home/JoinModal.tsx | 35 +++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/components/(main)/home/JoinModal.tsx diff --git a/src/app/(main)/home/page.tsx b/src/app/(main)/home/page.tsx index fed76a12..d31e121f 100644 --- a/src/app/(main)/home/page.tsx +++ b/src/app/(main)/home/page.tsx @@ -14,6 +14,7 @@ import { useAuth } from '@/context/AuthContext'; import { useRouter } from 'next/navigation'; import BottomButton from '@/components/(main)/home/BottomButton'; import WaitModal from '@/components/(main)/home/WaitModal'; +import JoinModal from '@/components/(main)/home/JoinModal'; import { isUserRegistered } from '@/utils/user'; import Border from '@/components/firstdate/Border'; import CustomButton from '@/components/(main)/home/CustomButton'; @@ -30,6 +31,9 @@ export default function Home() { const [interestedEvent, setInterestedEvent] = useState< 'first-date' | 'rup-peun' >('first-date'); + const [joinModal, setJoinModal] = useState(false); + const [announce, setAnnounce] = useState(false); + const [Isjoined, setIsJoined] = useState(false); useEffect(() => { getCurrentTime().then((res) => { @@ -102,6 +106,8 @@ export default function Home() { registered={!!user && isUserRegistered(user)} setWaitModal={setWaitModal} setEvent={setInterestedEvent} + setJoinModal={setJoinModal} + setAnnounce={setAnnounce} >
Rub Peun Kao Mai 2024
@@ -159,6 +165,12 @@ export default function Home() { setModal={setWaitModal} event={interestedEvent} /> + {}} + /> ); } diff --git a/src/components/(main)/home/CustomButton.tsx b/src/components/(main)/home/CustomButton.tsx index 76beb750..2b1e512a 100644 --- a/src/components/(main)/home/CustomButton.tsx +++ b/src/components/(main)/home/CustomButton.tsx @@ -11,6 +11,8 @@ interface CustomButtonProps { currentDate: Date; setWaitModal?: (value: boolean) => void; setEvent?: (value: 'first-date' | 'rup-peun') => void; + setJoinModal?: (value: boolean) => void; + setAnnounce?: (value: boolean) => void; } const CustomButton: React.FC = ({ @@ -21,6 +23,8 @@ const CustomButton: React.FC = ({ currentDate, setWaitModal, setEvent, + setJoinModal, + setAnnounce, }) => { const router = useRouter(); const firstdate = async () => { @@ -43,12 +47,26 @@ const CustomButton: React.FC = ({ }; const rubpeun = async () => { let rupPeunDate = currentDate; + let closedSelectionDate = currentDate; + let baanAnnounceDate = currentDate; const rupPeun = process.env.NEXT_PUBLIC_RUP_PEUN_DATE; + const closedSelection = process.env.NEXT_PUBLIC_CLOSED_BAAN_SELECTION_DATE; + const announce = process.env.NEXT_PUBLIC_BAAN_ANNOUNCEMENT_DATE; if (rupPeun) { rupPeunDate = new Date(rupPeun); } - console.log(currentDate.toISOString(), rupPeunDate.toISOString()); - if (currentDate >= rupPeunDate) { + if (closedSelection && announce) { + closedSelectionDate = new Date(closedSelection); + baanAnnounceDate = new Date(announce); + } + console.log(currentDate.toISOString(), rupPeunDate.toISOString(), closedSelectionDate.toISOString(), baanAnnounceDate.toISOString()); + if (currentDate >= closedSelectionDate){ + if (setJoinModal && setAnnounce){ + setJoinModal(true); + (currentDate >= baanAnnounceDate) ? setAnnounce(true) : setAnnounce(false); + } + } + else if (currentDate >= rupPeunDate && currentDate < closedSelectionDate) { if (registered) { router.push('/rpkm/baan/home'); } else { diff --git a/src/components/(main)/home/JoinModal.tsx b/src/components/(main)/home/JoinModal.tsx new file mode 100644 index 00000000..46f5a634 --- /dev/null +++ b/src/components/(main)/home/JoinModal.tsx @@ -0,0 +1,35 @@ +import React, { useEffect, useState } from 'react'; +import Modal from '@/components/rpkm/Modal/Modal'; +import BaseModal from '@/components/rpkm/Modal/BaseModal'; +import ModalButton from '@/components/rpkm/Modal/ModalButton'; +import modalStyles from '@/components/rpkm/Modal/ModalStyle'; + +interface JoinModalProps { + modal: boolean; + setModal: (value: boolean) => void; + announce: boolean; + setIsJoined: () => void; +} + +const JoinModal: React.FC = ({ modal, setModal, announce, setIsJoined}) => { + if (!modal) return null; + return ( + +
+

+ ยืนยันการเข้าร่วมงาน +

+

+ ยืนยันการเข้าร่วมงาน +

+
+
+ ); +}; + +export default JoinModal; \ No newline at end of file From 7250b723f4068af76577a117fca37d14a62f4134 Mon Sep 17 00:00:00 2001 From: PhorDotC Date: Wed, 24 Jul 2024 15:20:29 +0700 Subject: [PATCH 2/6] feat: closed selection UI --- public/success-white.svg | 9 +++ src/app/(main)/home/page.tsx | 7 ++- src/components/(main)/home/JoinModal.tsx | 80 +++++++++++++++++++----- src/components/rpkm/Modal/BaseModal.tsx | 2 +- src/components/rpkm/Modal/ModalStyle.ts | 9 +++ 5 files changed, 91 insertions(+), 16 deletions(-) create mode 100644 public/success-white.svg diff --git a/public/success-white.svg b/public/success-white.svg new file mode 100644 index 00000000..1a153c73 --- /dev/null +++ b/public/success-white.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/app/(main)/home/page.tsx b/src/app/(main)/home/page.tsx index d31e121f..856bd989 100644 --- a/src/app/(main)/home/page.tsx +++ b/src/app/(main)/home/page.tsx @@ -40,6 +40,10 @@ export default function Home() { setClientTime(res.currentTime); }); }, []); + + useEffect(() => { + console.log(Isjoined) + }, [Isjoined]); return ( <> @@ -169,7 +173,8 @@ export default function Home() { modal={joinModal} setModal={setJoinModal} announce={announce} - setIsJoined={()=>{}} + isJoined={Isjoined} + setIsJoined={setIsJoined} /> ); diff --git a/src/components/(main)/home/JoinModal.tsx b/src/components/(main)/home/JoinModal.tsx index 46f5a634..26c1fc24 100644 --- a/src/components/(main)/home/JoinModal.tsx +++ b/src/components/(main)/home/JoinModal.tsx @@ -1,5 +1,6 @@ import React, { useEffect, useState } from 'react'; -import Modal from '@/components/rpkm/Modal/Modal'; +import Image from 'next/image'; +import Success from '@public/success-white.svg' import BaseModal from '@/components/rpkm/Modal/BaseModal'; import ModalButton from '@/components/rpkm/Modal/ModalButton'; import modalStyles from '@/components/rpkm/Modal/ModalStyle'; @@ -8,28 +9,79 @@ interface JoinModalProps { modal: boolean; setModal: (value: boolean) => void; announce: boolean; - setIsJoined: () => void; + isJoined: boolean; + setIsJoined: (value: boolean) => void; } -const JoinModal: React.FC = ({ modal, setModal, announce, setIsJoined}) => { - if (!modal) return null; - return ( - = ({ modal, setModal, announce, isJoined, setIsJoined}) => { + if (!isJoined){ + const { button } = modalStyles['red']; + return ( + -
+
+

+ ยืนยันการเข้าร่วมงาน +

+

+ ยืนยันการเข้าร่วมงาน +

+
+
+ setModal(false)} + borderClassName={button['cancel-border']} + backgroundClassName={button['cancel-background']} + > + ยกเลิก + + { + setModal(false) + setIsJoined(true) + }} + borderClassName={button['accept-border']} + backgroundClassName={button['accept-background']} + > + ยืนยัน + +
+ + ); + } + const { button } = modalStyles['green']; + return ( + +
+ success

- ยืนยันการเข้าร่วมงาน + ยืนยันสำเร็จ!

- ยืนยันการเข้าร่วมงาน + แล้วพบกันวันที่ 3 สิงหาคม 2567

- - ); +
+ setIsJoined(false)} + borderClassName={button['cancel-border']} + backgroundClassName={button['cancel-background']} + > + กลับ + +
+
+ ); + }; export default JoinModal; \ No newline at end of file diff --git a/src/components/rpkm/Modal/BaseModal.tsx b/src/components/rpkm/Modal/BaseModal.tsx index b4a5fa08..30605710 100644 --- a/src/components/rpkm/Modal/BaseModal.tsx +++ b/src/components/rpkm/Modal/BaseModal.tsx @@ -3,7 +3,7 @@ import { cn } from '@/lib/utils'; import modalStyles from './ModalStyle'; interface ModalProps { - variant: 'red' | 'blue' | 'black'; + variant: 'red' | 'blue' | 'black' | 'green'; open: boolean; children: React.ReactNode; } diff --git a/src/components/rpkm/Modal/ModalStyle.ts b/src/components/rpkm/Modal/ModalStyle.ts index 57240230..3da58c00 100644 --- a/src/components/rpkm/Modal/ModalStyle.ts +++ b/src/components/rpkm/Modal/ModalStyle.ts @@ -26,6 +26,15 @@ const modalStyles = { 'cancel-border': 'bg-[#F5F5F5]', }, }, + green: { + background: 'bg-[#67AB88]', + button: { + 'accept-background': 'bg-[#C94B4B] text-[#EAE3C3]', + 'accept-border': 'bg-[#EAE3C3]', + 'cancel-background': 'bg-[#C94B4B] text-[#EAE3C3]', + 'cancel-border': 'bg-[#EAE3C3]', + } + } }; export default modalStyles; From ea22ca0876101f37feb383da69d7b737262f054e Mon Sep 17 00:00:00 2001 From: PhorDotC Date: Wed, 24 Jul 2024 22:28:00 +0700 Subject: [PATCH 3/6] feat: post check in rpkm --- src/app/(main)/home/page.tsx | 34 +++- src/app/(main)/layout.tsx | 3 +- src/components/(main)/home/CustomButton.tsx | 36 +++- src/components/(main)/home/JoinModal.tsx | 181 ++++++++++---------- src/components/rpkm/Modal/ModalStyle.ts | 4 +- 5 files changed, 154 insertions(+), 104 deletions(-) diff --git a/src/app/(main)/home/page.tsx b/src/app/(main)/home/page.tsx index 856bd989..8a2f719f 100644 --- a/src/app/(main)/home/page.tsx +++ b/src/app/(main)/home/page.tsx @@ -21,10 +21,13 @@ import CustomButton from '@/components/(main)/home/CustomButton'; import Link from 'next/link'; import { getMajorNameById } from '@/utils/register'; import { getCurrentTime } from '@/utils/time'; +import { createCheckIn } from '@/utils/checkin'; +import { CheckIn } from '@/types/checkIn'; +import toast from 'react-hot-toast'; export default function Home() { const router = useRouter(); - const { user, logout } = useAuth(); + const { user, resetContext, logout } = useAuth(); const [clientTime, setClientTime] = useState(new Date('1980-01-01')); const [qrModal, setQrModal] = useState(false); const [waitModal, setWaitModal] = useState(false); @@ -40,10 +43,29 @@ export default function Home() { setClientTime(res.currentTime); }); }, []); - - useEffect(() => { - console.log(Isjoined) - }, [Isjoined]); + + const checkInConfirm = async () => { + if (!user) { + return; + } + + try { + const checkInConfirm: CheckIn | null = await createCheckIn( + user.id, + user.email, + 'confirm-rpkm' + ); + + if (checkInConfirm) { + setIsJoined(true); + } else { + throw new Error('Error check in'); + } + resetContext(); + } catch (e) { + toast.error('ยืนยันไม่สำเร็จ'); + } + }; return ( <> @@ -174,7 +196,7 @@ export default function Home() { setModal={setJoinModal} announce={announce} isJoined={Isjoined} - setIsJoined={setIsJoined} + checkInConfirm={checkInConfirm} /> ); diff --git a/src/app/(main)/layout.tsx b/src/app/(main)/layout.tsx index 8ba72ec3..94d4d662 100644 --- a/src/app/(main)/layout.tsx +++ b/src/app/(main)/layout.tsx @@ -1,4 +1,5 @@ import Footer from '@/components/(main)/Footer'; +import BaanProvider from '@/context/BaanContext'; import React from 'react'; const layout = ({ @@ -8,7 +9,7 @@ const layout = ({ }>) => { return (
- {children} + {children}
); diff --git a/src/components/(main)/home/CustomButton.tsx b/src/components/(main)/home/CustomButton.tsx index 6a901978..28a5d48a 100644 --- a/src/components/(main)/home/CustomButton.tsx +++ b/src/components/(main)/home/CustomButton.tsx @@ -1,3 +1,5 @@ +import { useAuth } from '@/context/AuthContext'; +import { useBaan } from '@/context/BaanContext'; import { cn } from '@/lib/utils'; import { createEbookCount } from '@/utils/count'; import { useRouter } from 'next/navigation'; @@ -27,6 +29,8 @@ const CustomButton: React.FC = ({ setAnnounce, }) => { const router = useRouter(); + const { user } = useAuth(); + const { isConfirmed } = useBaan(); const firstdate = async () => { let firstDateDate = currentDate; const firstDate = process.env.NEXT_PUBLIC_FIRST_DATE_DATE; @@ -59,14 +63,30 @@ const CustomButton: React.FC = ({ closedSelectionDate = new Date(closedSelection); baanAnnounceDate = new Date(announce); } - console.log(currentDate.toISOString(), rupPeunDate.toISOString(), closedSelectionDate.toISOString(), baanAnnounceDate.toISOString()); - if (currentDate >= closedSelectionDate){ - if (setJoinModal && setAnnounce){ - setJoinModal(true); - (currentDate >= baanAnnounceDate) ? setAnnounce(true) : setAnnounce(false); + console.log( + currentDate.toISOString(), + rupPeunDate.toISOString(), + closedSelectionDate.toISOString(), + baanAnnounceDate.toISOString() + ); + if (currentDate >= closedSelectionDate) { + if (!isConfirmed) { + router.push('/rpkm/activities/home'); + } else if (setJoinModal && setAnnounce) { + const checkedIn = user?.checkIns.find( + (checkIn) => checkIn.event === 'confirm-rpkm' + ); + if (checkedIn) { + router.push('/rpkm/activities/home'); + } else { + setJoinModal(true); + //setBaanAnnouncementModal + } } - } - else if (currentDate >= rupPeunDate && currentDate < closedSelectionDate) { + } else if ( + currentDate >= rupPeunDate && + currentDate < closedSelectionDate + ) { if (registered) { router.push('/rpkm/baan/home'); } else { @@ -97,7 +117,7 @@ const CustomButton: React.FC = ({ onClick: rubpeun, }, 'e-book': { - color: 'bg-project-cream opacity-35 cursor-not-allowed', + color: 'bg-project-cream', onClick: ebook, }, 'contact-list': { diff --git a/src/components/(main)/home/JoinModal.tsx b/src/components/(main)/home/JoinModal.tsx index 26c1fc24..f2dccaeb 100644 --- a/src/components/(main)/home/JoinModal.tsx +++ b/src/components/(main)/home/JoinModal.tsx @@ -1,87 +1,94 @@ -import React, { useEffect, useState } from 'react'; -import Image from 'next/image'; -import Success from '@public/success-white.svg' -import BaseModal from '@/components/rpkm/Modal/BaseModal'; -import ModalButton from '@/components/rpkm/Modal/ModalButton'; -import modalStyles from '@/components/rpkm/Modal/ModalStyle'; - -interface JoinModalProps { - modal: boolean; - setModal: (value: boolean) => void; - announce: boolean; - isJoined: boolean; - setIsJoined: (value: boolean) => void; -} - -const JoinModal: React.FC = ({ modal, setModal, announce, isJoined, setIsJoined}) => { - if (!isJoined){ - const { button } = modalStyles['red']; - return ( - -
-

- ยืนยันการเข้าร่วมงาน -

-

- ยืนยันการเข้าร่วมงาน -

-
-
- setModal(false)} - borderClassName={button['cancel-border']} - backgroundClassName={button['cancel-background']} - > - ยกเลิก - - { - setModal(false) - setIsJoined(true) - }} - borderClassName={button['accept-border']} - backgroundClassName={button['accept-background']} - > - ยืนยัน - -
-
- ); - } - const { button } = modalStyles['green']; - return ( - -
- success -

- ยืนยันสำเร็จ! -

-

- แล้วพบกันวันที่ 3 สิงหาคม 2567 -

-
-
- setIsJoined(false)} - borderClassName={button['cancel-border']} - backgroundClassName={button['cancel-background']} - > - กลับ - -
-
- ); - -}; - -export default JoinModal; \ No newline at end of file +import { useRouter } from 'next/navigation'; +import Image from 'next/image'; +import Success from '@public/success-white.svg'; +import BaseModal from '@/components/rpkm/Modal/BaseModal'; +import ModalButton from '@/components/rpkm/Modal/ModalButton'; +import modalStyles from '@/components/rpkm/Modal/ModalStyle'; + +interface JoinModalProps { + modal: boolean; + setModal: (value: boolean) => void; + announce: boolean; + isJoined: boolean; + checkInConfirm: () => void; +} + +const JoinModal: React.FC = ({ + modal, + setModal, + announce, + isJoined, + checkInConfirm, +}) => { + const router = useRouter(); + + const HandleOnClick = () => { + router.push('/rpkm/activities/home'); + }; + + if (!isJoined) { + const { button } = modalStyles['red']; + return ( + +
+

+ ยืนยันการเข้าร่วมงาน +

+

ยืนยันการเข้าร่วมงาน

+
+
+ setModal(false)} + borderClassName={button['cancel-border']} + backgroundClassName={button['cancel-background']} + > + ยกเลิก + + { + setModal(false); + checkInConfirm(); + }} + borderClassName={button['accept-border']} + backgroundClassName={button['accept-background']} + > + ยืนยัน + +
+
+ ); + } + const { button } = modalStyles['green']; + return ( + +
+ success +

ยืนยันสำเร็จ!

+

+ แล้วพบกันวันที่ 3 สิงหาคม 2567 +

+
+
+ + ต่อไป + +
+
+ ); +}; + +export default JoinModal; diff --git a/src/components/rpkm/Modal/ModalStyle.ts b/src/components/rpkm/Modal/ModalStyle.ts index 3da58c00..14557bb0 100644 --- a/src/components/rpkm/Modal/ModalStyle.ts +++ b/src/components/rpkm/Modal/ModalStyle.ts @@ -33,8 +33,8 @@ const modalStyles = { 'accept-border': 'bg-[#EAE3C3]', 'cancel-background': 'bg-[#C94B4B] text-[#EAE3C3]', 'cancel-border': 'bg-[#EAE3C3]', - } - } + }, + }, }; export default modalStyles; From 2ddca7a9377c4acefa828b0abd2a36dd62c797e1 Mon Sep 17 00:00:00 2001 From: PhorDotC Date: Thu, 25 Jul 2024 02:06:22 +0700 Subject: [PATCH 4/6] feat: fetch checked in rpkm --- src/app/(main)/home/page.tsx | 32 +++++++++++++++++--- src/components/(main)/home/CustomButton.tsx | 9 ++---- src/dtos/checkInsDTO.ts | 24 ++++++++++++++- src/types/checkIn.ts | 9 ++++++ src/utils/checkin.ts | 33 +++++++++++++++++++-- 5 files changed, 93 insertions(+), 14 deletions(-) diff --git a/src/app/(main)/home/page.tsx b/src/app/(main)/home/page.tsx index 8a2f719f..95a42f6e 100644 --- a/src/app/(main)/home/page.tsx +++ b/src/app/(main)/home/page.tsx @@ -21,8 +21,8 @@ import CustomButton from '@/components/(main)/home/CustomButton'; import Link from 'next/link'; import { getMajorNameById } from '@/utils/register'; import { getCurrentTime } from '@/utils/time'; -import { createCheckIn } from '@/utils/checkin'; -import { CheckIn } from '@/types/checkIn'; +import { createCheckIn, fetchCheckIn } from '@/utils/checkin'; +import { CheckIn, GetCheckIn } from '@/types/checkIn'; import toast from 'react-hot-toast'; export default function Home() { @@ -36,12 +36,35 @@ export default function Home() { >('first-date'); const [joinModal, setJoinModal] = useState(false); const [announce, setAnnounce] = useState(false); - const [Isjoined, setIsJoined] = useState(false); + const [isCheckedIn, setIsCheckedIn] = useState(false); + const [isJoined, setIsJoined] = useState(false); useEffect(() => { getCurrentTime().then((res) => { setClientTime(res.currentTime); }); + + const checkedIn = async () => { + if (!user) { + return; + } + + try { + const checkedIns: GetCheckIn[] | null = await fetchCheckIn(); + if (checkedIns) { + const findEvent = !!checkedIns.find( + (checkIn) => checkIn.event === 'confirm-rpkm' + ); + setIsCheckedIn(findEvent); + } else { + throw new Error(''); + } + } catch (e) { + console.log('fetch check in', e); + } + }; + + checkedIn(); }, []); const checkInConfirm = async () => { @@ -132,6 +155,7 @@ export default function Home() { registered={!!user && isUserRegistered(user)} setWaitModal={setWaitModal} setEvent={setInterestedEvent} + isCheckedIn={isCheckedIn} setJoinModal={setJoinModal} setAnnounce={setAnnounce} > @@ -195,7 +219,7 @@ export default function Home() { modal={joinModal} setModal={setJoinModal} announce={announce} - isJoined={Isjoined} + isJoined={isJoined} checkInConfirm={checkInConfirm} /> diff --git a/src/components/(main)/home/CustomButton.tsx b/src/components/(main)/home/CustomButton.tsx index 28a5d48a..c5aa82e3 100644 --- a/src/components/(main)/home/CustomButton.tsx +++ b/src/components/(main)/home/CustomButton.tsx @@ -1,4 +1,3 @@ -import { useAuth } from '@/context/AuthContext'; import { useBaan } from '@/context/BaanContext'; import { cn } from '@/lib/utils'; import { createEbookCount } from '@/utils/count'; @@ -11,6 +10,7 @@ interface CustomButtonProps { children: React.ReactNode; registered?: boolean; currentDate: Date; + isCheckedIn?: boolean; setWaitModal?: (value: boolean) => void; setEvent?: (value: 'first-date' | 'rup-peun') => void; setJoinModal?: (value: boolean) => void; @@ -23,13 +23,13 @@ const CustomButton: React.FC = ({ children, registered, currentDate, + isCheckedIn, setWaitModal, setEvent, setJoinModal, setAnnounce, }) => { const router = useRouter(); - const { user } = useAuth(); const { isConfirmed } = useBaan(); const firstdate = async () => { let firstDateDate = currentDate; @@ -73,10 +73,7 @@ const CustomButton: React.FC = ({ if (!isConfirmed) { router.push('/rpkm/activities/home'); } else if (setJoinModal && setAnnounce) { - const checkedIn = user?.checkIns.find( - (checkIn) => checkIn.event === 'confirm-rpkm' - ); - if (checkedIn) { + if (isCheckedIn) { router.push('/rpkm/activities/home'); } else { setJoinModal(true); diff --git a/src/dtos/checkInsDTO.ts b/src/dtos/checkInsDTO.ts index c6e3a768..1a56ee14 100644 --- a/src/dtos/checkInsDTO.ts +++ b/src/dtos/checkInsDTO.ts @@ -1,4 +1,4 @@ -import { CheckIn, ChildCheckIn } from '@/types/checkIn'; +import { CheckIn, ChildCheckIn, GetCheckIn } from '@/types/checkIn'; export type ChildCheckInDTO = { email: string; @@ -20,6 +20,17 @@ export type CheckInDTO = { lastname: string; }; +export type GetCheckInDTO = { + checkins: { + email: string; + event: string; + id: string; + user_id: string; + timestamp: string; + is_duplicate: boolean; + }[]; +}; + export const ChildCheckInParser = ( checkinDTO: ChildCheckInDTO ): ChildCheckIn => { @@ -45,3 +56,14 @@ export const CheckInParser = (checkinDTO: CheckInDTO): CheckIn => { lastName: checkinDTO.lastname, }; }; + +export const GetCheckInParser = (checkinDTO: GetCheckInDTO): GetCheckIn[] => { + return checkinDTO.checkins.map((checkin) => ({ + email: checkin.email, + event: checkin.event, + id: checkin.id, + userId: checkin.user_id, + timestamp: checkin.timestamp, + isDuplicate: checkin.is_duplicate, + })); +}; diff --git a/src/types/checkIn.ts b/src/types/checkIn.ts index 1a2f00be..b5179782 100644 --- a/src/types/checkIn.ts +++ b/src/types/checkIn.ts @@ -17,3 +17,12 @@ export type CheckIn = { firstName: string; lastName: string; }; + +export type GetCheckIn = { + email: string; + event: string; + id: string; + userId: string; + timestamp: string; + isDuplicate: boolean; +}; diff --git a/src/utils/checkin.ts b/src/utils/checkin.ts index 0e843d98..222e8266 100644 --- a/src/utils/checkin.ts +++ b/src/utils/checkin.ts @@ -1,8 +1,12 @@ import { AxiosResponse } from 'axios'; import { apiClient } from './axios'; -import { getAccessToken } from './auth'; -import { CheckIn } from '@/types/checkIn'; -import { CheckInParser } from '@/dtos/checkInsDTO'; +import { getAccessToken, getUserId } from './auth'; +import { CheckIn, GetCheckIn } from '@/types/checkIn'; +import { + CheckInParser, + GetCheckInDTO, + GetCheckInParser, +} from '@/dtos/checkInsDTO'; export const createCheckIn = async ( userID: string, @@ -34,3 +38,26 @@ export const createCheckIn = async ( return null; } }; + +export const fetchCheckIn = async (): Promise => { + const accessToken = await getAccessToken(); + const userId = await getUserId(); + + if (!accessToken || !userId) { + return null; + } + + try { + const res: AxiosResponse = await apiClient.get( + `/checkin/${userId}`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + } + ); + return GetCheckInParser(res.data); + } catch (error) { + return null; + } +}; From 75fc8903b06fae62fad76615e3e44d8f6a477add Mon Sep 17 00:00:00 2001 From: PhorDotC Date: Thu, 25 Jul 2024 02:15:25 +0700 Subject: [PATCH 5/6] fix: lint --- src/app/(main)/home/page.tsx | 4 +--- src/components/(main)/home/CustomButton.tsx | 4 +--- src/components/(main)/home/JoinModal.tsx | 2 -- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/app/(main)/home/page.tsx b/src/app/(main)/home/page.tsx index 95a42f6e..70667b0a 100644 --- a/src/app/(main)/home/page.tsx +++ b/src/app/(main)/home/page.tsx @@ -35,7 +35,7 @@ export default function Home() { 'first-date' | 'rup-peun' >('first-date'); const [joinModal, setJoinModal] = useState(false); - const [announce, setAnnounce] = useState(false); + //const [announce, setAnnounce] = useState(false); const [isCheckedIn, setIsCheckedIn] = useState(false); const [isJoined, setIsJoined] = useState(false); @@ -157,7 +157,6 @@ export default function Home() { setEvent={setInterestedEvent} isCheckedIn={isCheckedIn} setJoinModal={setJoinModal} - setAnnounce={setAnnounce} >
Rub Peun Kao Mai 2024
@@ -218,7 +217,6 @@ export default function Home() { diff --git a/src/components/(main)/home/CustomButton.tsx b/src/components/(main)/home/CustomButton.tsx index c5aa82e3..77dbe7e2 100644 --- a/src/components/(main)/home/CustomButton.tsx +++ b/src/components/(main)/home/CustomButton.tsx @@ -14,7 +14,6 @@ interface CustomButtonProps { setWaitModal?: (value: boolean) => void; setEvent?: (value: 'first-date' | 'rup-peun') => void; setJoinModal?: (value: boolean) => void; - setAnnounce?: (value: boolean) => void; } const CustomButton: React.FC = ({ @@ -27,7 +26,6 @@ const CustomButton: React.FC = ({ setWaitModal, setEvent, setJoinModal, - setAnnounce, }) => { const router = useRouter(); const { isConfirmed } = useBaan(); @@ -72,7 +70,7 @@ const CustomButton: React.FC = ({ if (currentDate >= closedSelectionDate) { if (!isConfirmed) { router.push('/rpkm/activities/home'); - } else if (setJoinModal && setAnnounce) { + } else if (setJoinModal) { if (isCheckedIn) { router.push('/rpkm/activities/home'); } else { diff --git a/src/components/(main)/home/JoinModal.tsx b/src/components/(main)/home/JoinModal.tsx index f2dccaeb..291dc8bd 100644 --- a/src/components/(main)/home/JoinModal.tsx +++ b/src/components/(main)/home/JoinModal.tsx @@ -8,7 +8,6 @@ import modalStyles from '@/components/rpkm/Modal/ModalStyle'; interface JoinModalProps { modal: boolean; setModal: (value: boolean) => void; - announce: boolean; isJoined: boolean; checkInConfirm: () => void; } @@ -16,7 +15,6 @@ interface JoinModalProps { const JoinModal: React.FC = ({ modal, setModal, - announce, isJoined, checkInConfirm, }) => { From 6be846f04dbb98c08b8f3f20b2b714931b7ecef9 Mon Sep 17 00:00:00 2001 From: teegoood Date: Thu, 25 Jul 2024 02:51:06 +0700 Subject: [PATCH 6/6] fix route protect bug and change Sidebar --- .../activities/details/community/page.tsx | 1 + src/app/rpkm/activities/map/page.tsx | 2 +- src/components/rpkm/Sidebar/Menu.tsx | 20 +++++++++---------- src/context/AuthContext.tsx | 14 ++++++++++++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/app/rpkm/activities/details/community/page.tsx b/src/app/rpkm/activities/details/community/page.tsx index a8adf793..08c2d4fd 100644 --- a/src/app/rpkm/activities/details/community/page.tsx +++ b/src/app/rpkm/activities/details/community/page.tsx @@ -88,6 +88,7 @@ const Page = () => { href="https://lin.ee/i9Ezhg7" borderClassName="bg-rpkm-cream" backgroundClassName="bg-rpkm-green text-center text-lg text-rpkm-gray w-[60vw]" + target="_self" > Line OA ของกิจกรรม diff --git a/src/app/rpkm/activities/map/page.tsx b/src/app/rpkm/activities/map/page.tsx index b8d1a25c..522d2e9d 100644 --- a/src/app/rpkm/activities/map/page.tsx +++ b/src/app/rpkm/activities/map/page.tsx @@ -28,7 +28,7 @@ const page = () => { '1.5px 1.5px 0 #000, -1.5px -1.5px 0 #000, 1.5px -1.5px 0 #000, -1.5px 1.5px 0 #000', }} > - ข้อมูลที่จัดแต่ละกิจกรรม + กิจกรรมชุมชน
diff --git a/src/components/rpkm/Sidebar/Menu.tsx b/src/components/rpkm/Sidebar/Menu.tsx index 79d764eb..91ce82e7 100644 --- a/src/components/rpkm/Sidebar/Menu.tsx +++ b/src/components/rpkm/Sidebar/Menu.tsx @@ -9,8 +9,8 @@ function Menu() { return (
ลงทะเบียนเลือกบ้าน @@ -82,19 +82,19 @@ function Menu() { aria-label="Accordion 2" title={
แผนที่
} > -
+
+
+ ข้อมูลที่จัดแต่ละกิจกรรม +
- ข้อมูลที่จัดแต่ละกิจกรรม - -
กิจกรรมชุมชน -
+
diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx index 83df4f6d..d522fa9e 100644 --- a/src/context/AuthContext.tsx +++ b/src/context/AuthContext.tsx @@ -121,6 +121,18 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ ); const now = (await getCurrentTime()).currentTime; + console.log( + 'now', + now, + 'firstdate', + firstdate, + 'startRPKM', + startRPKM, + 'endBannSelect', + endBannSelect, + 'freshyNight', + freshyNight + ); //firstdate if (path.includes('firstdate')) { if (now < firstdate) { @@ -135,7 +147,7 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ } // end baan select - if (path.includes('/baan')) { + if (path.includes('rpkm/baan')) { if (now > endBannSelect) { return router.push('/rpkm/activities/home'); }