diff --git a/src/app/(main)/edit/page.tsx b/src/app/(main)/edit/page.tsx index e3128861..b4a76a01 100644 --- a/src/app/(main)/edit/page.tsx +++ b/src/app/(main)/edit/page.tsx @@ -46,7 +46,7 @@ export default function Edit() { lastname: user?.lastname || '', nickname: user?.nickname || '', faculty: user?.faculty || '', - year: user?.year || 0, + year: user?.year || 1, tel: user?.tel || '', parent_tel: user?.parentTel || '', parent: user?.parent || '', @@ -59,10 +59,17 @@ export default function Edit() { const handleInputChange = ( e: ChangeEvent ) => { + let value: string = e.target.value; + if (['tel', 'parent_tel'].includes(e.target.name)) { + value = + '0123456789'.includes(value.at(-1) || '') && value.length <= 10 + ? value + : value.slice(0, -1); + } + setFormData({ ...formData, - [e.target.name]: - e.target.name === 'year' ? +e.target.value : e.target.value, + [e.target.name]: e.target.name === 'year' ? +value : value, }); }; @@ -74,8 +81,8 @@ export default function Edit() { if (!formData.nickname) formErrors.push('nickname'); if (!formData.faculty) formErrors.push('faculty'); if (!formData.year) formErrors.push('year'); - if (!formData.tel) formErrors.push('tel'); - if (!formData.parent_tel) formErrors.push('parent_tel'); + if (formData.tel.length != 10) formErrors.push('tel'); + if (formData.parent_tel.length != 10) formErrors.push('parent_tel'); if (!formData.parent) formErrors.push('parent'); setErrors(formErrors); @@ -157,8 +164,7 @@ export default function Edit() { - - + @@ -301,30 +307,44 @@ export default function Edit() {

ข้อมูลด้านสุขภาพ

- - - + +
+ + + + + +
) => { + let value: string = e.target.value; + if (['tel', 'parent_tel'].includes(e.target.name)) { + value = + '0123456789'.includes(value.at(-1) || '') && value.length <= 10 + ? value + : value.slice(0, -1); + } + setFormData({ ...formData, - [e.target.name]: - e.target.name === 'year' ? +e.target.value : e.target.value, + [e.target.name]: e.target.name === 'year' ? +value : value, }); }; @@ -85,8 +92,8 @@ export default function Register() { if (!formData.year) stepErrors.push('year'); break; case 2: - if (!formData.tel) stepErrors.push('tel'); - if (!formData.parent_tel) stepErrors.push('parent_tel'); + if (formData.tel.length != 10) stepErrors.push('tel'); + if (formData.parent_tel.length != 10) stepErrors.push('parent_tel'); if (!formData.parent) stepErrors.push('parent'); break; case 3: @@ -184,8 +191,7 @@ export default function Register() { - - +
diff --git a/src/app/(main)/staff/edit/page.tsx b/src/app/(main)/staff/edit/page.tsx index eb011675..d8137fb8 100644 --- a/src/app/(main)/staff/edit/page.tsx +++ b/src/app/(main)/staff/edit/page.tsx @@ -43,10 +43,17 @@ export default function Edit() { const handleInputChange = ( e: ChangeEvent ) => { + let value: string = e.target.value; + if (['tel', 'parent_tel'].includes(e.target.name)) { + value = + '0123456789'.includes(value.at(-1) || '') && value.length <= 10 + ? value + : value.slice(0, -1); + } + setFormData({ ...formData, - [e.target.name]: - e.target.name === 'year' ? +e.target.value : e.target.value, + [e.target.name]: e.target.name === 'year' ? +value : value, }); }; @@ -58,7 +65,7 @@ export default function Edit() { if (!formData.nickname) formErrors.push('nickname'); if (!formData.faculty) formErrors.push('faculty'); if (!formData.year) formErrors.push('year'); - if (!formData.tel) formErrors.push('tel'); + if (formData.tel.length != 10) formErrors.push('tel'); setErrors(formErrors); const isError = formErrors.length !== 0; @@ -90,7 +97,7 @@ export default function Edit() { setUpload(true); toast.success('เเก้ไขข้อมูลสำเร็จ'); await resetContext(); - router.push('/home'); + router.push('/firstdate/staff/profile'); }); } }; @@ -140,8 +147,7 @@ export default function Edit() { - - + @@ -223,6 +229,10 @@ export default function Edit() { + + + + @@ -256,7 +266,7 @@ export default function Edit() { diff --git a/src/app/(main)/staff/register/page.tsx b/src/app/(main)/staff/register/page.tsx index aa57cf63..d7872f35 100644 --- a/src/app/(main)/staff/register/page.tsx +++ b/src/app/(main)/staff/register/page.tsx @@ -46,10 +46,17 @@ export default function Register() { const handleInputChange = ( e: ChangeEvent ) => { + let value: string = e.target.value; + if (['tel', 'parent_tel'].includes(e.target.name)) { + value = + '0123456789'.includes(value.at(-1) || '') && value.length <= 10 + ? value + : value.slice(0, -1); + } + setFormData({ ...formData, - [e.target.name]: - e.target.name === 'year' ? +e.target.value : e.target.value, + [e.target.name]: e.target.name === 'year' ? +value : value, }); }; @@ -66,7 +73,7 @@ export default function Register() { if (!formData.nickname) stepErrors.push('nickname'); if (!formData.faculty) stepErrors.push('faculty'); if (!formData.year) stepErrors.push('year'); - if (!formData.tel) stepErrors.push('tel'); + if (formData.tel.length != 10) stepErrors.push('tel'); break; } @@ -115,7 +122,7 @@ export default function Register() { toast.success('ลงทะเบียนสำเร็จ'); const isStaff = user.role == 'staff'; - const newPath = isStaff ? '/staff/home' : '/registered'; + const newPath = isStaff ? '/firstdate/staff/home' : '/register-done'; await resetContext(); router.push(newPath); @@ -154,8 +161,7 @@ export default function Register() { - - + diff --git a/src/app/dev/page.tsx b/src/app/dev/page.tsx deleted file mode 100644 index 7aeb2c12..00000000 --- a/src/app/dev/page.tsx +++ /dev/null @@ -1,31 +0,0 @@ -'use client'; - -import Border from '@/components/Border'; -import { Suspense } from 'react'; -import UserCard from '@/components/UserCard'; - -// For dev (delete soon) -export default function page() { - return ( - - - - ); -} - -function Login() { - return ( - - - -
- -
- - {/* Break if the size is too small because the texts' sizes */} -
- -
-
- ); -} diff --git a/src/app/firstdate/staff/profile/page.tsx b/src/app/firstdate/staff/profile/page.tsx index ef619ee5..b812c1ec 100644 --- a/src/app/firstdate/staff/profile/page.tsx +++ b/src/app/firstdate/staff/profile/page.tsx @@ -8,6 +8,7 @@ import { useAuth } from '@/context/AuthContext'; import Border from '@/components/firstdate/Border'; import MenuList from '@/components/firstdate/MenuList'; import { getMajorNameById } from '@/utils/register'; +import Link from 'next/link'; export default function AdminInfo() { const { user, logout } = useAuth(); @@ -34,6 +35,12 @@ export default function AdminInfo() {
{user?.firstname}
#{user?.year}
+ + +
{user && getMajorNameById(user?.faculty)}
diff --git a/src/app/page.tsx b/src/app/page.tsx index 0a7ff976..a390e589 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -62,7 +62,7 @@ function Login() { let newPath; if (isStaff) { - newPath = isRegistered ? '/staff/home' : '/staff/register'; + newPath = isRegistered ? '/firstdate/staff/home' : '/staff/register'; } else { newPath = isRegistered ? '/home' : '/register'; } diff --git a/src/app/rpkm/activities/[category]/page.tsx b/src/app/rpkm/activities/[category]/page.tsx new file mode 100644 index 00000000..420e11cc --- /dev/null +++ b/src/app/rpkm/activities/[category]/page.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +const page = () => { + return
page
; +}; + +export default page; diff --git a/src/app/rpkm/activities/details/[id]/page.tsx b/src/app/rpkm/activities/details/[id]/page.tsx new file mode 100644 index 00000000..420e11cc --- /dev/null +++ b/src/app/rpkm/activities/details/[id]/page.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +const page = () => { + return
page
; +}; + +export default page; diff --git a/src/app/rpkm/activities/home/page.tsx b/src/app/rpkm/activities/home/page.tsx new file mode 100644 index 00000000..420e11cc --- /dev/null +++ b/src/app/rpkm/activities/home/page.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +const page = () => { + return
page
; +}; + +export default page; diff --git a/src/app/rpkm/activities/map/page.tsx b/src/app/rpkm/activities/map/page.tsx new file mode 100644 index 00000000..420e11cc --- /dev/null +++ b/src/app/rpkm/activities/map/page.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +const page = () => { + return
page
; +}; + +export default page; diff --git a/src/app/rpkm/baan/baan-select/page.tsx b/src/app/rpkm/baan/baan-select/page.tsx new file mode 100644 index 00000000..420e11cc --- /dev/null +++ b/src/app/rpkm/baan/baan-select/page.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +const page = () => { + return
page
; +}; + +export default page; diff --git a/src/app/rpkm/baan/home/page.tsx b/src/app/rpkm/baan/home/page.tsx new file mode 100644 index 00000000..420e11cc --- /dev/null +++ b/src/app/rpkm/baan/home/page.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +const page = () => { + return
page
; +}; + +export default page; diff --git a/src/app/rpkm/page.tsx b/src/app/rpkm/page.tsx new file mode 100644 index 00000000..b6650cb9 --- /dev/null +++ b/src/app/rpkm/page.tsx @@ -0,0 +1,14 @@ +'use client'; + +import UserCard from '@/components/UserCard'; +import React from 'react'; + +const page = () => { + return ( +
+ +
+ ); +}; + +export default page; diff --git a/src/components/(main)/pdpa/index.tsx b/src/components/(main)/pdpa/index.tsx index 21e49ec8..4c227235 100644 --- a/src/components/(main)/pdpa/index.tsx +++ b/src/components/(main)/pdpa/index.tsx @@ -68,62 +68,64 @@ export default function Pdpa(props: PdpaProps) {
-

PDPA

-
-

- {titles.map((title, index) => ( -

{title}

- ))} -

-
- {description.map((section, index) => ( -

- {section} -

- ))} -
-
-
- setIsChecked(!isChecked)} - /> - {isChecked && ( - +

PDPA

+
+

+ {titles.map((title, index) => ( +

{title}

+ ))} +

+
+ {description.map((section, index) => ( +

- - - )} + {section} +

+ ))} +
+
+
+ setIsChecked(!isChecked)} + /> + {isChecked && ( + + + + )} +
+
- + รับทราบและยินยอม +
-
); diff --git a/src/components/UserCard.tsx b/src/components/UserCard.tsx index e0726aa7..b2e86fc9 100644 --- a/src/components/UserCard.tsx +++ b/src/components/UserCard.tsx @@ -10,7 +10,7 @@ const UserCard = () => { const { user } = useAuth(); const name = `${user?.firstname} ${user?.lastname}`; const studentId = user?.email.split('@')[0]; - const photo_url = user?.photo_url; + const photoUrl = user?.photoUrl; return (
@@ -21,9 +21,9 @@ const UserCard = () => { />
- {photo_url && ( + {photoUrl && ( user-picture diff --git a/src/components/firstdate/MenuIcon.tsx b/src/components/firstdate/MenuIcon.tsx index 83379d8b..563d6286 100644 --- a/src/components/firstdate/MenuIcon.tsx +++ b/src/components/firstdate/MenuIcon.tsx @@ -13,7 +13,7 @@ const MenuIcon = (props: MenuIconProps) => { const { isActive, handleOnClick, name, iconify } = props; return ( -
+
{ @@ -40,13 +40,24 @@ export default function MenuList({ isRewardPage }: TwoCircleMenuProps) { } }, [user]); + const isShowReward = useMemo(() => { + return ( + giftCondition && + giftCondition.status != 'isStaff' && + giftCondition.status != 'recieved' && + !isRewardPage + ); + }, [giftCondition, isRewardPage]); + + console.log(giftCondition); + return (
- {giftCondition && ( + {giftCondition && isShowReward && ( )} {user && ( @@ -58,7 +69,7 @@ export default function MenuList({ isRewardPage }: TwoCircleMenuProps) { handleOnClick={() => handleNavigate('profile')} iconify="icon-park-solid:people" /> - {!isRewardPage && giftCondition?.status != 'recieved' && ( + {giftCondition && isShowReward && (
= ({ }; const handleConfirm = () => { + if (inputValue.length < 1) { + return toast.error('กรุณากรอกข้อมูล'); + } onSubmit(activityId, inputValue); onClose(); }; diff --git a/src/components/firstdate/home/modal/OpinionModal.tsx b/src/components/firstdate/home/modal/OpinionModal.tsx index f0ea7c4c..0e220871 100644 --- a/src/components/firstdate/home/modal/OpinionModal.tsx +++ b/src/components/firstdate/home/modal/OpinionModal.tsx @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import TextModal from '@/components/firstdate/home/modal/TextModal'; +import toast from 'react-hot-toast'; interface OpinionModalProps { activityId: string; @@ -19,6 +20,9 @@ const OpinionModal: React.FC = ({ }; const handleConfirm = () => { + if (inputValue.length < 1) { + return toast.error('กรุณากรอกข้อมูล'); + } onSubmit(activityId, inputValue); onClose(); }; diff --git a/src/components/firstdate/home/modal/TextModal.tsx b/src/components/firstdate/home/modal/TextModal.tsx index c2ab8a3b..f7ca5958 100644 --- a/src/components/firstdate/home/modal/TextModal.tsx +++ b/src/components/firstdate/home/modal/TextModal.tsx @@ -8,7 +8,7 @@ import Image from 'next/image'; interface ModalProps { title: string; placeholder: string; - onClose: () => void; + onClose?: () => void; value?: string; onChange?: (e: React.ChangeEvent) => void; onClick?: () => void; @@ -18,14 +18,13 @@ interface ModalProps { const Modal: React.FC = ({ title, placeholder, - onClose, value, onChange, onClick, children, }) => { return ( -
+
= ({
- handleClick(index)} - /> + {index < 5 && ( + handleClick(index)} + /> + )}
); diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx index 8a8acc27..e4b3cff7 100644 --- a/src/context/AuthContext.tsx +++ b/src/context/AuthContext.tsx @@ -65,9 +65,10 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ const isStaff = userObj.role == 'staff'; const isStaffPage = path.includes('/staff'); const isRegistered = isUserRegistered(userObj); + const isRegisterPage = path.includes('register'); if (isStaff) { - if (!isRegistered) { + if (!isRegistered && !isRegisterPage) { return router.push('/staff/register'); } @@ -75,7 +76,7 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ return router.push('/firstdate/staff/home'); } } else { - if (!isRegistered) { + if (!isRegistered && !isRegisterPage) { return router.push('/register'); } diff --git a/src/utils/reward.ts b/src/utils/reward.ts index 8835f69c..5eabd2db 100644 --- a/src/utils/reward.ts +++ b/src/utils/reward.ts @@ -1,6 +1,6 @@ import { User } from '@/types/user'; -export type Status = 'ready' | 'not-ready' | 'recieved'; +export type Status = 'ready' | 'not-ready' | 'recieved' | 'isStaff'; export const getReceiveGiftCondition = ( user: User @@ -9,6 +9,13 @@ export const getReceiveGiftCondition = ( throw new Error('there is no user'); } + if (user.role == 'staff') { + return { + score: 0, + status: 'isStaff', + }; + } + let workshop = 0; let landmark = 0; let club = 0; @@ -24,7 +31,7 @@ export const getReceiveGiftCondition = ( }); const score = workshop + club + landmark; - const isReceivedGift = user.receiveGift >= 0; + const isReceivedGift = user.receiveGift > 0; const isValidPoint = !!workshop && !!club && !!landmark && score >= 6; let status: Status; diff --git a/src/utils/user.ts b/src/utils/user.ts index b069bb9c..aef49486 100644 --- a/src/utils/user.ts +++ b/src/utils/user.ts @@ -55,12 +55,8 @@ export const patchReward = async (): Promise => { export const isUserRegistered = (user: User): boolean => { return ( - !!user.faculty && !!user.firstname && !!user.lastname && - !!user.nickname && - !!user.parent && - !!user.parentTel && !!user.tel && !!user.title && !!user.year