ลงทะเบียนเลือกบ้าน
@@ -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');
}
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;
+ }
+};