@@ -17,21 +17,10 @@ import { PasswordField } from "components/FormElementsv2/PasswordField/PasswordF
17
17
18
18
import FormHeader from "./FormHeader" ;
19
19
import { FieldCell , FieldTitleCell , PasswordValidationSchema } from "./Common" ;
20
- import { customerUserResetPassword } from "src/api/customer-user" ;
21
- import { Box , CircularProgress } from "@mui/material" ;
22
- import Divider from "src/components/Divider/Divider" ;
23
- import BrokenCircleCheckIcon from "app/(dashboard)/components/Icons/BrokenCircleCheckIcon" ;
24
20
25
- type PasswordFormProps = {
26
- email : string ;
27
- } ;
28
-
29
- const PasswordForm : React . FC < PasswordFormProps > = ( { email } ) => {
21
+ const PasswordForm = ( ) => {
30
22
const snackbar = useSnackbar ( ) ;
31
23
const { logout } = useLogout ( ) ;
32
- const loggedInUsingSSO = localStorage . getItem ( "loggedInUsingSSO" ) ;
33
-
34
- const isLoggedInUsingSSO = loggedInUsingSSO === "true" ;
35
24
36
25
const updatePasswordMutation = useMutation (
37
26
( data : any ) =>
@@ -69,173 +58,95 @@ const PasswordForm: React.FC<PasswordFormProps> = ({ email }) => {
69
58
70
59
const { values, handleChange, handleBlur, touched, errors } = formData ;
71
60
72
- const setPasswordMutation = useMutation (
73
- ( ) => {
74
- const payload = { email : email } ;
75
- return customerUserResetPassword ( payload ) ;
76
- } ,
77
- {
78
- onSuccess : ( ) => {
79
- snackbar . showSuccess (
80
- "We have emailed you a link to set your password. Please check your email and follow the instructions."
81
- ) ;
82
- } ,
83
- }
84
- ) ;
85
-
86
- const handleSetPassword = ( ) => {
87
- setPasswordMutation . mutate ( ) ;
88
- } ;
89
- if ( ! isLoggedInUsingSSO ) {
90
- return (
91
- < div >
92
- < FormHeader
93
- title = "Password"
94
- description = "Please enter your current password to change your password"
95
- className = "pb-5 mb-6 border-b border-[#E9EAEB]"
96
- />
97
-
98
- { /* @ts -ignore */ }
99
- < Form onSubmit = { formData . handleSubmit } >
100
- < div className = "grid grid-cols-1 lg:grid-cols-4 gap-y-5" >
101
- < FieldTitleCell >
102
- < FieldTitle required > Current Password</ FieldTitle >
103
- </ FieldTitleCell >
104
- < FieldCell >
105
- < PasswordField
106
- name = "currentPassword"
107
- id = "currentPassword"
108
- value = { values . currentPassword }
109
- onChange = { handleChange }
110
- onBlur = { handleBlur }
111
- sx = { { mt : 0 } }
112
- />
113
- < FieldError >
114
- { touched . currentPassword && errors . currentPassword }
115
- </ FieldError >
116
- </ FieldCell >
117
-
118
- < FieldTitleCell >
119
- < FieldTitle required > New Password</ FieldTitle >
120
- </ FieldTitleCell >
121
- < FieldCell >
122
- < Text
123
- size = "small"
124
- weight = "regular"
125
- color = "#535862"
126
- sx = { { mb : "6px" } }
127
- >
128
- Your new password must be more than 8 characters
129
- </ Text >
130
- < PasswordField
131
- name = "newPassword"
132
- id = "newPassword"
133
- value = { values . newPassword }
134
- onChange = { handleChange }
135
- onBlur = { handleBlur }
136
- sx = { { mt : 0 } }
137
- />
138
- < FieldError >
139
- { touched . newPassword && errors . newPassword }
140
- </ FieldError >
141
- </ FieldCell >
142
-
143
- < FieldTitleCell >
144
- < FieldTitle required > Confirm Password</ FieldTitle >
145
- </ FieldTitleCell >
146
- < FieldCell >
147
- < PasswordField
148
- name = "confirmPassword"
149
- id = "confirmPassword"
150
- value = { values . confirmPassword }
151
- onChange = { handleChange }
152
- onBlur = { handleBlur }
153
- sx = { { mt : 0 } }
154
- />
155
- < FieldError >
156
- { touched . confirmPassword && errors . confirmPassword }
157
- </ FieldError >
158
- </ FieldCell >
159
- </ div >
160
-
161
- < div className = "flex items-center justify-end gap-4 mt-5" >
162
- < Button
163
- variant = "outlined"
164
- onClick = { ( ) => formData . resetForm ( ) }
165
- disabled = { updatePasswordMutation . isLoading }
166
- >
167
- Cancel
168
- </ Button >
169
- < Button
170
- type = "submit"
171
- variant = "contained"
172
- disabled = { updatePasswordMutation . isLoading }
173
- >
174
- Save
175
- { updatePasswordMutation . isLoading && < LoadingSpinnerSmall /> }
176
- </ Button >
177
- </ div >
178
- </ Form >
179
- </ div >
180
- ) ;
181
- }
182
-
183
- if ( isLoggedInUsingSSO ) {
184
- return (
185
- < Box sx = { { Padding : "100px" } } display = "flex" flexDirection = { "column" } >
186
- < Box display = "flex" justifyContent = { "center" } >
187
- < Box
188
- display = "flex"
189
- gap = { 1 }
190
- mt = "2px"
191
- textAlign = { "center" }
192
- alignItems = { "center" }
193
- >
194
- < BrokenCircleCheckIcon color = "#079455" />
195
-
196
- < Text size = "xlarge" weight = "regular" color = "rgba(83, 88, 98, 1)" >
197
- You are currently logged in via Google/Github SSO.
198
- </ Text >
199
- </ Box >
200
- </ Box >
201
- < Box display = "flex" justifyContent = { "center" } >
202
- < Box display = "flex" gap = { 1 } mt = "2px" >
203
- < Text size = "xlarge" weight = "regular" color = "rgba(83, 88, 98, 1)" >
204
- To setup password-based access, please
205
- </ Text >
206
- < Button
207
- onClick = { handleSetPassword }
208
- sx = { {
209
- color : "#7F56D9 !important" ,
210
- fontSize : "20px !important" ,
211
- lineHeight : "30px !important" ,
212
- fontWeight : 700 ,
213
- textDecoration : "underline !important" ,
214
- textUnderlineOffset : "2px" ,
215
- cursor : "pointer" ,
216
- background : "none" ,
217
- border : "none" ,
218
- padding : "0 !important" ,
219
- } }
220
- disabled = { setPasswordMutation . isLoading }
61
+ return (
62
+ < div >
63
+ < FormHeader
64
+ title = "Password"
65
+ description = "Please enter your current password to change your password"
66
+ className = "pb-5 mb-6 border-b border-[#E9EAEB]"
67
+ />
68
+
69
+ { /* @ts -ignore */ }
70
+ < Form onSubmit = { formData . handleSubmit } >
71
+ < div className = "grid grid-cols-1 lg:grid-cols-4 gap-y-5" >
72
+ < FieldTitleCell >
73
+ < FieldTitle required > Current Password</ FieldTitle >
74
+ </ FieldTitleCell >
75
+ < FieldCell >
76
+ < PasswordField
77
+ name = "currentPassword"
78
+ id = "currentPassword"
79
+ value = { values . currentPassword }
80
+ onChange = { handleChange }
81
+ onBlur = { handleBlur }
82
+ sx = { { mt : 0 } }
83
+ />
84
+ < FieldError >
85
+ { touched . currentPassword && errors . currentPassword }
86
+ </ FieldError >
87
+ </ FieldCell >
88
+
89
+ < FieldTitleCell >
90
+ < FieldTitle required > New Password</ FieldTitle >
91
+ </ FieldTitleCell >
92
+ < FieldCell >
93
+ < Text
94
+ size = "small"
95
+ weight = "regular"
96
+ color = "#535862"
97
+ sx = { { mb : "6px" } }
221
98
>
222
- click here
223
- </ Button >
224
-
225
- < Text size = "xlarge" weight = "regular" color = "rgba(83, 88, 98, 1)" >
226
- to send a setup link
99
+ Your new password must be more than 8 characters
227
100
</ Text >
228
- </ Box >
229
- </ Box >
230
- < Box display = "flex" justifyContent = { "center" } >
231
- { setPasswordMutation . isLoading && (
232
- < CircularProgress size = { 16 } sx = { { marginLeft : "8px" } } />
233
- ) }
234
- </ Box >
235
- < Divider sx = { { mt : 3 , mb : 3 } } />
236
- </ Box >
237
- ) ;
238
- }
101
+ < PasswordField
102
+ name = "newPassword"
103
+ id = "newPassword"
104
+ value = { values . newPassword }
105
+ onChange = { handleChange }
106
+ onBlur = { handleBlur }
107
+ sx = { { mt : 0 } }
108
+ />
109
+ < FieldError > { touched . newPassword && errors . newPassword } </ FieldError >
110
+ </ FieldCell >
111
+
112
+ < FieldTitleCell >
113
+ < FieldTitle required > Confirm Password</ FieldTitle >
114
+ </ FieldTitleCell >
115
+ < FieldCell >
116
+ < PasswordField
117
+ name = "confirmPassword"
118
+ id = "confirmPassword"
119
+ value = { values . confirmPassword }
120
+ onChange = { handleChange }
121
+ onBlur = { handleBlur }
122
+ sx = { { mt : 0 } }
123
+ />
124
+ < FieldError >
125
+ { touched . confirmPassword && errors . confirmPassword }
126
+ </ FieldError >
127
+ </ FieldCell >
128
+ </ div >
129
+
130
+ < div className = "flex items-center justify-end gap-4 mt-5" >
131
+ < Button
132
+ variant = "outlined"
133
+ onClick = { ( ) => formData . resetForm ( ) }
134
+ disabled = { updatePasswordMutation . isLoading }
135
+ >
136
+ Cancel
137
+ </ Button >
138
+ < Button
139
+ type = "submit"
140
+ variant = "contained"
141
+ disabled = { updatePasswordMutation . isLoading }
142
+ >
143
+ Save
144
+ { updatePasswordMutation . isLoading && < LoadingSpinnerSmall /> }
145
+ </ Button >
146
+ </ div >
147
+ </ Form >
148
+ </ div >
149
+ ) ;
239
150
} ;
240
151
241
152
export default PasswordForm ;
0 commit comments