From 96084b22c040b828c1556c81c05194a3faa6d10b Mon Sep 17 00:00:00 2001 From: amel Date: Thu, 26 Dec 2024 15:15:45 +0800 Subject: [PATCH] upd: user Deskripsi: - tambah input select jabatan pada edit profile - tambah loading pada input select jabatan halaman edit profile - tambah loading pada input select jabatan halaman edit member No Issues --- src/app/api/user/profile/route.ts | 5 +- src/module/user/member/ui/edit_member.tsx | 19 +- src/module/user/member/ui/tab_list_member.tsx | 11 +- src/module/user/profile/lib/type_profile.ts | 1 + src/module/user/profile/ui/edit_profile.tsx | 339 ++++++++++-------- 5 files changed, 214 insertions(+), 161 deletions(-) diff --git a/src/app/api/user/profile/route.ts b/src/app/api/user/profile/route.ts index 96d8d85..4676f6e 100644 --- a/src/app/api/user/profile/route.ts +++ b/src/app/api/user/profile/route.ts @@ -66,7 +66,7 @@ export async function PUT(request: Request) { const file = body.get("file") as File; const data = body.get("data"); - const { name, email, phone, nik, gender } = JSON.parse(data as string) + const { name, email, phone, nik, gender, idPosition } = JSON.parse(data as string) const cekNIK = await prisma.user.count({ where: { @@ -108,7 +108,8 @@ export async function PUT(request: Request) { email: email, phone: "62" + phone, nik: nik, - gender: gender + gender: gender, + idPosition: idPosition }, select: { img: true diff --git a/src/module/user/member/ui/edit_member.tsx b/src/module/user/member/ui/edit_member.tsx index c67d99d..f9acc2e 100644 --- a/src/module/user/member/ui/edit_member.tsx +++ b/src/module/user/member/ui/edit_member.tsx @@ -30,6 +30,7 @@ export default function EditMember({ id }: { id: string }) { const [loading, setLoading] = useState(true) const roleLogin = useHookstate(globalRole) const tema = useHookstate(TEMA) + const [loadingPosition, setLoadingPosition] = useState(true) const [touched, setTouched] = useState({ nik: false, name: false, @@ -83,6 +84,7 @@ export default function EditMember({ id }: { id: string }) { async function getAllPosition(val: any) { try { + setLoadingPosition(true) const res = await funGetAllPosition( "?active=true" + "&group=" + `${val}` ); @@ -90,6 +92,8 @@ export default function EditMember({ id }: { id: string }) { } catch (error) { console.error(error) + } finally { + setLoadingPosition(false) } } @@ -233,19 +237,14 @@ export default function EditMember({ id }: { id: string }) { } {loading ? - <> - - - - - - - - + [...Array(6)].map((_, index) => ( + + )) : <> ({ + value: data.id, + label: data.name, + })) + : [] + } + onChange={(val: any) => { onValidation('idPosition', val) }} + value={(data?.idPosition == "") ? null : data.idPosition} + error={ + touched.idPosition && ( + data.idPosition == "" || String(data.idPosition) == "null" ? "Jabatan Tidak Boleh Kosong" : null ) - ? "Email tidak valid" - : null) - } - /> - +62} - onChange={(e) => { onValidation('phone', e.target.value); }} - value={data.phone} - error={ - touched.phone && - (data.phone == "" ? "Nomor Telepon Tidak Boleh Kosong" - : !(data.phone.length >= 10 && data.phone.length <= 15) ? "Nomor Telepon Tidak Valid" : null) - } - /> - { onValidation('gender', val) }} + value={data.gender} + error={ + touched.gender && + (data.gender == "" || data.gender == null ? "Jenis Kelamin Tidak Boleh Kosong" : null) + } + /> + + )}