11import * as Common from "@frontend/common" ;
2- import { ContentCopy , KeyOff } from "@mui/icons-material" ;
3- import {
4- Button ,
5- ButtonProps ,
6- CircularProgress ,
7- Dialog ,
8- DialogActions ,
9- DialogContent ,
10- DialogContentText ,
11- DialogTitle ,
12- IconButton ,
13- InputAdornment ,
14- TextField ,
15- } from "@mui/material" ;
2+ import { KeyOff } from "@mui/icons-material" ;
3+ import { Button , ButtonProps , CircularProgress , Dialog , DialogActions , DialogContent , DialogContentText , DialogTitle } from "@mui/material" ;
164import { ErrorBoundary , Suspense } from "@suspensive/react" ;
175import * as React from "react" ;
18- import { useParams } from "react-router-dom" ;
6+ import { useNavigate , useParams } from "react-router-dom" ;
197
20- import { addErrorSnackbar , addSnackbar } from "../../../utils/snackbar" ;
8+ import { PasswordResultDialog } from "./password_result_dialog" ;
9+ import { addErrorSnackbar } from "../../../utils/snackbar" ;
2110import { AdminEditor } from "../../layouts/admin_editor" ;
2211
2312type PageStateType = {
2413 isConfirmDialogOpen : boolean ;
2514 isResultDialogOpen : boolean ;
2615 newPassword : string | null ;
16+ createdUserId : string | null ;
2717} ;
2818
2919export const AdminUserExtEditor : React . FC = ErrorBoundary . with (
3020 { fallback : Common . Components . ErrorFallback } ,
3121 Suspense . with ( { fallback : < CircularProgress /> } , ( ) => {
3222 const { id } = useParams < { id ?: string } > ( ) ;
23+ const navigate = useNavigate ( ) ;
3324 const [ pageState , setPageState ] = React . useState < PageStateType > ( {
3425 isConfirmDialogOpen : false ,
3526 isResultDialogOpen : false ,
3627 newPassword : null ,
28+ createdUserId : null ,
3729 } ) ;
3830 const openConfirmDialog = ( ) => setPageState ( ( ps ) => ( { ...ps , isConfirmDialogOpen : true } ) ) ;
3931 const closeConfirmDialog = ( ) => setPageState ( ( ps ) => ( { ...ps , isConfirmDialogOpen : false } ) ) ;
40- const closeResultDialog = ( ) => setPageState ( ( ps ) => ( { ...ps , isResultDialogOpen : false , newPassword : null } ) ) ;
32+ const closeResultDialog = ( ) => {
33+ const userId = pageState . createdUserId ;
34+ setPageState ( ( ps ) => ( { ...ps , isResultDialogOpen : false , newPassword : null , createdUserId : null } ) ) ;
35+ if ( userId ) navigate ( `/user/userext/${ userId } ` ) ;
36+ } ;
4137
4238 const backendAdminClient = Common . Hooks . BackendAdminAPI . useBackendAdminClient ( ) ;
4339 const useResetPasswordMutation = Common . Hooks . BackendAdminAPI . useResetUserPasswordMutation ( backendAdminClient , id || "" ) ;
@@ -58,13 +54,13 @@ export const AdminUserExtEditor: React.FC = ErrorBoundary.with(
5854 }
5955 } ;
6056
61- const copyPasswordToClipboard = ( ) => {
62- if ( pageState . newPassword ) {
63- navigator . clipboard . writeText ( pageState . newPassword ) . then (
64- ( ) => addSnackbar ( "비밀번호가 클립보드에 복사되었습니다." , "success" ) ,
65- ( ) => addSnackbar ( "클립보드 복사에 실패했습니다." , "error" )
66- ) ;
67- }
57+ const onCreated = ( data : Record < string , string > ) => {
58+ setPageState ( ( ps ) => ( {
59+ ... ps ,
60+ isResultDialogOpen : true ,
61+ newPassword : data . password ,
62+ createdUserId : data . id ,
63+ } ) ) ;
6864 } ;
6965
7066 const resetUserPasswordButton : ButtonProps = {
@@ -91,35 +87,9 @@ export const AdminUserExtEditor: React.FC = ErrorBoundary.with(
9187 </ DialogActions >
9288 </ Dialog >
9389
94- < Dialog open = { pageState . isResultDialogOpen } maxWidth = "sm" fullWidth >
95- < DialogTitle > 비밀번호가 초기화되었습니다</ DialogTitle >
96- < DialogContent >
97- < DialogContentText sx = { { mb : 2 } } >
98- 새로운 비밀번호가 생성되었습니다. 이 비밀번호는 다시 확인할 수 없으니 반드시 복사해 두세요.
99- </ DialogContentText >
100- < TextField
101- fullWidth
102- value = { pageState . newPassword || "" }
103- slotProps = { {
104- input : {
105- readOnly : true ,
106- endAdornment : (
107- < InputAdornment position = "end" >
108- < IconButton onClick = { copyPasswordToClipboard } edge = "end" >
109- < ContentCopy />
110- </ IconButton >
111- </ InputAdornment >
112- ) ,
113- } ,
114- } }
115- />
116- </ DialogContent >
117- < DialogActions >
118- < Button onClick = { closeResultDialog } > 닫기</ Button >
119- </ DialogActions >
120- </ Dialog >
90+ < PasswordResultDialog open = { pageState . isResultDialogOpen } password = { pageState . newPassword } onClose = { closeResultDialog } />
12191
122- < AdminEditor app = "user" resource = "userext" id = { id } extraActions = { [ resetUserPasswordButton ] } />
92+ < AdminEditor app = "user" resource = "userext" id = { id } extraActions = { [ resetUserPasswordButton ] } onCreated = { onCreated } />
12393 </ >
12494 ) ;
12595 } )
0 commit comments