Skip to content

Commit ce3c512

Browse files
committed
feat: 유저 비밀번호 초기화 버튼 추가
1 parent 9f330e4 commit ce3c512

File tree

1 file changed

+75
-0
lines changed
  • apps/pyconkr-admin/src/components/pages/user

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import * as Common from "@frontend/common";
2+
import { KeyOff } from "@mui/icons-material";
3+
import {
4+
Button,
5+
ButtonProps,
6+
CircularProgress,
7+
Dialog,
8+
DialogActions,
9+
DialogContent,
10+
DialogContentText,
11+
DialogTitle,
12+
} from "@mui/material";
13+
import { ErrorBoundary, Suspense } from "@suspensive/react";
14+
import * as React from "react";
15+
import { useParams } from "react-router-dom";
16+
17+
import { addErrorSnackbar, addSnackbar } from "../../../utils/snackbar";
18+
import { AdminEditor } from "../../layouts/admin_editor";
19+
20+
type PageStateType = {
21+
isDialogOpen: boolean;
22+
};
23+
24+
export const AdminUserExtEditor: React.FC = ErrorBoundary.with(
25+
{ fallback: Common.Components.ErrorFallback },
26+
Suspense.with({ fallback: <CircularProgress /> }, () => {
27+
const { id } = useParams<{ id?: string }>();
28+
const [pageState, setPageState] = React.useState<PageStateType>({ isDialogOpen: false });
29+
const openDialog = () => setPageState((ps) => ({ ...ps, isDialogOpen: true }));
30+
const closeDialog = () => setPageState((ps) => ({ ...ps, isDialogOpen: false }));
31+
32+
const backendAdminClient = Common.Hooks.BackendAdminAPI.useBackendAdminClient();
33+
const useResetPasswordMutation = Common.Hooks.BackendAdminAPI.useResetUserPasswordMutation(
34+
backendAdminClient,
35+
id || ""
36+
);
37+
38+
const resetUserPassword = () => {
39+
closeDialog();
40+
if (id) {
41+
useResetPasswordMutation.mutate(undefined, {
42+
onSuccess: () => addSnackbar("비밀번호가 초기화되었습니다.", "success"),
43+
onError: addErrorSnackbar,
44+
});
45+
}
46+
};
47+
48+
const resetUserPasswordButton: ButtonProps = {
49+
variant: "outlined",
50+
color: "error",
51+
size: "small",
52+
startIcon: <KeyOff />,
53+
children: "비밀번호 초기화",
54+
onClick: () => id && openDialog(),
55+
};
56+
57+
return (
58+
<>
59+
<Dialog open={pageState.isDialogOpen}>
60+
<DialogTitle>비밀번호 초기화</DialogTitle>
61+
<DialogContent>
62+
<DialogContentText>정말 이 사용자의 비밀번호를 초기화하시겠습니까?</DialogContentText>
63+
</DialogContent>
64+
<DialogActions>
65+
<Button color="error" onClick={closeDialog} autoFocus>
66+
취소
67+
</Button>
68+
<Button onClick={resetUserPassword}>초기화</Button>
69+
</DialogActions>
70+
</Dialog>
71+
<AdminEditor app="user" resource="userext" id={id} extraActions={[resetUserPasswordButton]} />
72+
</>
73+
);
74+
})
75+
);

0 commit comments

Comments
 (0)