188 lines
6.3 KiB
TypeScript
188 lines
6.3 KiB
TypeScript
"use client";
|
|
|
|
import dayjs from "dayjs";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
|
import {
|
|
Button,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableRow,
|
|
} from "@common/components";
|
|
import { USER_STATE_CODE, UserApi, PasswordResetDialog } from "@/entities/user";
|
|
import { ENDPOINT } from "@/shared/config";
|
|
import { useAlertStore, useMutationWrapper } from "@/shared/lib";
|
|
|
|
function UserDetail({ userUnqId }: { userUnqId: string }) {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const { confirm } = useConfirm();
|
|
const queryClient = useQueryClient();
|
|
const alert = useAlertStore((state) => state.setMessage);
|
|
|
|
const { data, refetch } = useQuery({
|
|
queryKey: [ENDPOINT.USER_SERVICE.USERS, userUnqId],
|
|
queryFn: () => UserApi.findByUserUnqId(userUnqId),
|
|
enabled: !!userUnqId,
|
|
});
|
|
|
|
const { mutate: onLockUser } = useMutationWrapper({
|
|
mutationFn: () => UserApi.lockUser(userUnqId),
|
|
onSuccess: () => {
|
|
alert("계정 잠금이 활성화 되었습니다.");
|
|
refetch();
|
|
},
|
|
});
|
|
|
|
const { mutate: onUnlockUser } = useMutationWrapper({
|
|
mutationFn: () => UserApi.unlockUser(userUnqId),
|
|
onSuccess: () => {
|
|
alert("계정 잠금이 해제되었습니다.");
|
|
refetch();
|
|
},
|
|
});
|
|
|
|
const { mutate: onApplyUser } = useMutationWrapper({
|
|
mutationFn: () => UserApi.applyUser(userUnqId),
|
|
onSuccess: () => {
|
|
alert("사용자 승인이 완료되었습니다.");
|
|
refetch();
|
|
},
|
|
});
|
|
|
|
const { mutateAsync: deleteUser } = useMutationWrapper({
|
|
mutationFn: () => UserApi.deleteUser(userUnqId),
|
|
onSuccess: () => {
|
|
alert("회원이 삭제되었습니다.", router.back);
|
|
queryClient.invalidateQueries({
|
|
queryKey: [ENDPOINT.USER_SERVICE.USERS],
|
|
});
|
|
},
|
|
});
|
|
|
|
const handleDelete = async () => {
|
|
if (await confirm("삭제하시겠습니까?")) {
|
|
await deleteUser();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="card card-border !mt-6">
|
|
<div className="card-header">
|
|
<h3 className="text-2xl font-medium text-label">회원 정보</h3>
|
|
</div>
|
|
<div className="card">
|
|
<div className="mb-4 flex justify-end gap-2">
|
|
{data?.userStateCode === USER_STATE_CODE.정지 ? (
|
|
<Button color="orange" onClick={() => onUnlockUser()}>
|
|
<i className="diveicon di-lock-open" />
|
|
잠금해제
|
|
</Button>
|
|
) : (
|
|
<Button color="orange" onClick={() => onLockUser()}>
|
|
<i className="diveicon di-lock" />
|
|
계정잠금
|
|
</Button>
|
|
)}
|
|
<PasswordResetDialog userUnqId={userUnqId}>
|
|
<Button color="gray">
|
|
<i className="diveicon di-arrow-reset" /> 비밀번호 초기화
|
|
</Button>
|
|
</PasswordResetDialog>
|
|
{data?.userStateCode === USER_STATE_CODE.대기 && (
|
|
<Button className="emerald" onClick={() => onApplyUser()}>
|
|
<i className="diveicon di-check-circle-line" /> 가입승인
|
|
</Button>
|
|
)}
|
|
</div>
|
|
<Table variant="secondary">
|
|
<colgroup>
|
|
<col width="20%" />
|
|
<col width="80%" />
|
|
</colgroup>
|
|
<TableBody>
|
|
<TableRow>
|
|
<TableHead>아이디</TableHead>
|
|
<TableCell className="!px-4">{data?.userId}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>이름</TableHead>
|
|
<TableCell className="!px-4">{data?.userName}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead rowSpan={2}>연락처</TableHead>
|
|
<TableCell className="!px-4">휴대폰: {data?.mphn}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableCell className="!px-4">전화번호: {data?.telno}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>이메일</TableHead>
|
|
<TableCell className="!px-4">{data?.email}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead rowSpan={2}>주소</TableHead>
|
|
<TableCell className="!px-4">
|
|
{data?.zip && `(${data?.zip})`} {data?.addr}
|
|
</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableCell className="!px-4">{data?.daddr}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>기관구분</TableHead>
|
|
<TableCell className="!px-4">{data?.ogdpSeNm}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>세부기관</TableHead>
|
|
<TableCell className="!px-4">{data?.dtlInstNm}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>소속</TableHead>
|
|
<TableCell className="!px-4">{data?.laeSeNm}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>환경청</TableHead>
|
|
<TableCell className="!px-4">{data?.ecoNm}</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>가입일</TableHead>
|
|
<TableCell className="!px-4">
|
|
{data?.regDt ? dayjs(data?.regDt).format("YYYY-MM-DD") : ""}
|
|
</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>최근로그인</TableHead>
|
|
<TableCell className="!px-4">
|
|
{data?.lastLoginDate
|
|
? dayjs(data?.lastLoginDate).format("YYYY-MM-DD HH:mm:ss")
|
|
: ""}
|
|
</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableHead>계정상태</TableHead>
|
|
<TableCell className="!px-4">{data?.userStateNm}</TableCell>
|
|
</TableRow>
|
|
</TableBody>
|
|
</Table>
|
|
</div>
|
|
<div className="flex justify-center gap-4 pb-12 pt-10">
|
|
<Button size="lg" className="white" onClick={router.back}>
|
|
목록
|
|
</Button>
|
|
<Button size="lg" onClick={() => router.push(`${pathname}/modify`)}>
|
|
수정
|
|
</Button>
|
|
<Button size="lg" color="red" onClick={handleDelete}>
|
|
삭제
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export { UserDetail };
|