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
This commit is contained in:
amel
2024-12-26 15:15:45 +08:00
parent 87c90c94c4
commit 96084b22c0
5 changed files with 214 additions and 161 deletions

View File

@@ -66,7 +66,7 @@ export async function PUT(request: Request) {
const file = body.get("file") as File; const file = body.get("file") as File;
const data = body.get("data"); 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({ const cekNIK = await prisma.user.count({
where: { where: {
@@ -108,7 +108,8 @@ export async function PUT(request: Request) {
email: email, email: email,
phone: "62" + phone, phone: "62" + phone,
nik: nik, nik: nik,
gender: gender gender: gender,
idPosition: idPosition
}, },
select: { select: {
img: true img: true

View File

@@ -30,6 +30,7 @@ export default function EditMember({ id }: { id: string }) {
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const roleLogin = useHookstate(globalRole) const roleLogin = useHookstate(globalRole)
const tema = useHookstate(TEMA) const tema = useHookstate(TEMA)
const [loadingPosition, setLoadingPosition] = useState(true)
const [touched, setTouched] = useState({ const [touched, setTouched] = useState({
nik: false, nik: false,
name: false, name: false,
@@ -83,6 +84,7 @@ export default function EditMember({ id }: { id: string }) {
async function getAllPosition(val: any) { async function getAllPosition(val: any) {
try { try {
setLoadingPosition(true)
const res = await funGetAllPosition( const res = await funGetAllPosition(
"?active=true" + "&group=" + `${val}` "?active=true" + "&group=" + `${val}`
); );
@@ -90,6 +92,8 @@ export default function EditMember({ id }: { id: string }) {
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} finally {
setLoadingPosition(false)
} }
} }
@@ -233,19 +237,14 @@ export default function EditMember({ id }: { id: string }) {
</Indicator> </Indicator>
} }
{loading ? {loading ?
<> [...Array(6)].map((_, index) => (
<Skeleton height={40} mt={20} radius={30} /> <Skeleton key={index} height={40} mt={20} radius={30} />
<Skeleton height={40} mt={10} radius={30} /> ))
<Skeleton height={40} mt={10} radius={30} />
<Skeleton height={40} mt={10} radius={30} />
<Skeleton height={40} mt={10} radius={30} />
<Skeleton height={40} mt={10} radius={30} />
<Skeleton height={40} mt={10} radius={30} />
</>
: :
<> <>
<Select <Select
placeholder="Pilih Jabatan" label="Jabatan" w={"100%"} size="md" required withAsterisk radius={30} placeholder={loadingPosition ? "Loading.. " : "Pilih Jabatan"}
label="Jabatan" w={"100%"} size="md" required withAsterisk radius={30}
styles={{ styles={{
input: { input: {
color: tema.get().utama, color: tema.get().utama,

View File

@@ -10,6 +10,7 @@ import { HiMagnifyingGlass } from "react-icons/hi2"
import { useWibuRealtime } from "wibu-realtime" import { useWibuRealtime } from "wibu-realtime"
import { funGetAllmember } from "../lib/api_member" import { funGetAllmember } from "../lib/api_member"
import { IListMember } from "../lib/type_member" import { IListMember } from "../lib/type_member"
import { funGetUserByCookies } from "@/module/auth"
export default function TabListMember() { export default function TabListMember() {
@@ -32,16 +33,18 @@ export default function TabListMember() {
project: "sdm" project: "sdm"
}) })
const [isRefresh, setRefresh] = useState(false) const [isRefresh, setRefresh] = useState(false)
const [userLogin, setUserLogin] = useState<any>('')
async function getAllUser(loading: boolean) { async function getAllUser(loading: boolean) {
try { try {
if (loading) setLoading(loading)
setLoading(true)
const res = await funGetAllmember('?active=' + status + '&group=' + group + '&search=' + searchQuery + '&page=' + isPage) const res = await funGetAllmember('?active=' + status + '&group=' + group + '&search=' + searchQuery + '&page=' + isPage)
const user = await funGetUserByCookies()
if (res.success) { if (res.success) {
setNameGroup(res.filter.name) setNameGroup(res.filter.name)
setIdGroup(res.filter.id) setIdGroup(res.filter.id)
setUserLogin(user.id)
if (isPage == 1) { if (isPage == 1) {
setDataMember(res.data) setDataMember(res.data)
} else { } else {
@@ -148,9 +151,7 @@ export default function TabListMember() {
dataMember.map((v, i) => { dataMember.map((v, i) => {
return ( return (
<Box my={10} key={i}> <Box my={10} key={i}>
<Box onClick={() => { <Box onClick={() => { userLogin == v.id ? router.push(`/profile`) : router.push(`/member/${v.id}`) }}>
router.push(`/member/${v.id}`)
}}>
<Grid p={5} align="center"> <Grid p={5} align="center">
<Grid.Col <Grid.Col
span={{ span={{

View File

@@ -18,5 +18,6 @@ export interface IEditDataProfile {
phone: string; phone: string;
email: string; email: string;
gender: string; gender: string;
idPosition: string;
img: string; img: string;
} }

View File

@@ -12,10 +12,13 @@ import toast from "react-hot-toast";
import { FaCamera } from "react-icons/fa6"; import { FaCamera } from "react-icons/fa6";
import { funEditProfileByCookies, funGetProfileByCookies, } from "../lib/api_profile"; import { funEditProfileByCookies, funGetProfileByCookies, } from "../lib/api_profile";
import { IEditDataProfile, IProfileById } from "../lib/type_profile"; import { IEditDataProfile, IProfileById } from "../lib/type_profile";
import { IDataPositionMember } from "../../member/lib/type_member";
import { funGetAllPosition } from "@/module/position/lib/api_position";
export default function EditProfile() { export default function EditProfile() {
const [isValModal, setValModal] = useState(false); const [isValModal, setValModal] = useState(false);
const [isDataEdit, setDataEdit] = useState<IProfileById[]>([]); const [isDataEdit, setDataEdit] = useState<IProfileById[]>([]);
const [listPosition, setListPosition] = useState<IDataPositionMember[]>([])
const openRef = useRef<() => void>(null); const openRef = useRef<() => void>(null);
const [img, setIMG] = useState<any | null>(); const [img, setIMG] = useState<any | null>();
const [imgForm, setImgForm] = useState<any>(); const [imgForm, setImgForm] = useState<any>();
@@ -23,6 +26,7 @@ export default function EditProfile() {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const tema = useHookstate(TEMA); const tema = useHookstate(TEMA);
const [loadingKonfirmasi, setLoadingKonfirmasi] = useState(false); const [loadingKonfirmasi, setLoadingKonfirmasi] = useState(false);
const [loadingPosition, setLoadingPosition] = useState(true)
const [touched, setTouched] = useState({ const [touched, setTouched] = useState({
nik: false, nik: false,
@@ -30,6 +34,7 @@ export default function EditProfile() {
phone: false, phone: false,
email: false, email: false,
gender: false, gender: false,
idPosition: false
}); });
const [data, setData] = useState<IEditDataProfile>({ const [data, setData] = useState<IEditDataProfile>({
@@ -40,13 +45,30 @@ export default function EditProfile() {
email: "", email: "",
gender: "", gender: "",
img: "", img: "",
idPosition: ""
}); });
async function getAllPosition(val: any) {
try {
setLoadingPosition(true)
const res = await funGetAllPosition(
"?active=true" + "&group=" + `${val}`
);
setListPosition(res.data);
} catch (error) {
console.error(error)
} finally {
setLoadingPosition(false)
}
}
async function getAllProfile() { async function getAllProfile() {
try { try {
setLoading(true); setLoading(true);
const res = await funGetProfileByCookies(); const res = await funGetProfileByCookies();
setData(res.data); setData(res.data);
getAllPosition(res.data.idGroup);
setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`); setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`);
setLoading(false); setLoading(false);
} catch (error) { } catch (error) {
@@ -111,7 +133,7 @@ export default function EditProfile() {
} }
} else if (kategori == 'phone') { } else if (kategori == 'phone') {
setData({ ...data, phone: val }) setData({ ...data, phone: val })
if (val == "" || !(val.length >= 10 && val.length <= 15)) { if (val == "" || !(val.length >= 9 && val.length <= 15)) {
setTouched({ ...touched, phone: true }) setTouched({ ...touched, phone: true })
} else { } else {
setTouched({ ...touched, phone: false }) setTouched({ ...touched, phone: false })
@@ -130,6 +152,13 @@ export default function EditProfile() {
} else { } else {
setTouched({ ...touched, gender: false }) setTouched({ ...touched, gender: false })
} }
} else if (kategori == 'idPosition') {
setData({ ...data, idPosition: val })
if (val == "" || String(val) == "null") {
setTouched({ ...touched, idPosition: true })
} else {
setTouched({ ...touched, idPosition: false })
}
} }
} }
@@ -181,16 +210,38 @@ export default function EditProfile() {
/> />
</Indicator> </Indicator>
)} )}
{loading ? ( {loading ?
<> [...Array(6)].map((_, index) => (
<Skeleton height={40} mt={20} radius={10} /> <Skeleton key={index} height={40} mt={20} radius={10} />
<Skeleton height={40} mt={20} radius={10} /> ))
<Skeleton height={40} mt={20} radius={10} /> : (
<Skeleton height={40} mt={20} radius={10} />
<Skeleton height={40} mt={20} radius={10} />
</>
) : (
<> <>
<Select
placeholder={loadingPosition ? "Loading.. " : "Pilih Jabatan"}
label="Jabatan" w={"100%"} size="md" required withAsterisk radius={10}
styles={{
input: {
color: tema.get().utama,
borderRadius: tema.get().utama,
borderColor: tema.get().utama,
},
}}
data={
listPosition
? listPosition.map((data) => ({
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
)
}
/>
<TextInput <TextInput
size="md" size="md"
type="number" type="number"
@@ -288,7 +339,7 @@ export default function EditProfile() {
error={ error={
touched.phone && touched.phone &&
(data.phone == "" ? "Nomor Telepon Tidak Boleh Kosong" (data.phone == "" ? "Nomor Telepon Tidak Boleh Kosong"
: !(data.phone.length >= 10 && data.phone.length <= 15) ? "Nomor Telepon Tidak Valid" : null) : !(data.phone.length >= 9 && data.phone.length <= 15) ? "Nomor Telepon Tidak Valid" : null)
} }
/> />
<Select <Select