1- import { Button , Checkbox , FormControl , FormControlLabel , TextField } from '@mui/material' ;
2- import { Launch } from '@mui/icons- material' ;
1+ import { ErrorOutline , Launch } from '@mui/icons- material' ;
2+ import { Alert , Button , Checkbox , FormControl , FormControlLabel , TextField } from '@mui/material' ;
33import { withStyles } from '@mui/styles' ;
4+ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs' ;
45import { DatePicker } from '@mui/x-date-pickers/DatePicker' ;
56import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider' ;
6- import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs' ;
77import dayjs from 'dayjs' ;
88import utc from 'dayjs/plugin/utc' ;
99import PropTypes from 'prop-types' ;
1010import React , { Suspense , useEffect , useRef , useState } from 'react' ;
11- import styled from 'styled-components' ;
1211import CopyToClipboard from 'react-copy-to-clipboard' ;
12+ import styled from 'styled-components' ;
13+ import DesignTokenColors from '../../common/components/Style/DesignTokenColors' ;
14+ import generateRandomString from '../../common/utils/generateRandomString' ;
1315import { renderLog } from '../../common/utils/logging' ;
1416import webAppConfig from '../../config' ;
1517import { useConnectAppContext } from '../../contexts/ConnectAppContext' ;
1618import { viewerCanSeeOrDo } from '../../models/AuthModel' ;
17- import { ActionOption , ActionOptionContainerLeft8 , ActionOptionContainerOverflow , ActionOptionList } from '../Style/actionOptionStyles' ;
1819import makeRequestParams from '../../react-query/makeRequestParams' ;
1920import { usePersonSaveMutation } from '../../react-query/mutations' ;
21+ import weConnectQueryFn , { METHOD } from '../../react-query/WeConnectQuery' ;
22+ import { ActionOption , ActionOptionContainerLeft8 , ActionOptionContainerOverflow , ActionOptionList } from '../Style/actionOptionStyles' ;
2023import { SpanWithLinkStyle } from '../Style/linkStyles' ;
2124import EmailOfficialManager from './EmailOfficialManager' ;
22- import DesignTokenColors from '../../common/components/Style/DesignTokenColors' ;
23- import weConnectQueryFn , { METHOD } from '../../react-query/WeConnectQuery' ;
24- import generateRandomString from '../../common/utils/generateRandomString' ;
2525
2626
2727dayjs . extend ( utc ) ;
@@ -40,6 +40,7 @@ const EditPersonForm = ({ classes }) => {
4040 const [ saveButtonActive , setSaveButtonActive ] = useState ( false ) ;
4141 const [ showEmailPreferred , setShowEmailPreferred ] = useState ( false ) ;
4242 const [ showFirstNamePreferred , setShowFirstNamePreferred ] = useState ( false ) ;
43+ const [ emailError , setEmailError ] = useState ( '' ) ;
4344 const [ showCompletedOnboardingCheckboxes , setShowCompletedOnboardingCheckboxes ] = useState ( false ) ;
4445 const [ initialPerson ] = useState ( getAppContextValue ( 'profileDrawerPerson' ) ) ;
4546 // const [initialPerson] = useState(useGetPersonById(getAppContextValue('profileDrawerPersonId')));
@@ -186,20 +187,32 @@ const EditPersonForm = ({ classes }) => {
186187 // console.log('activePerson:', activePerson);
187188
188189
189- const wevoteUserClick = async ( ) => {
190- const primaryEmail = activePerson . emailOfficial ;
190+ const resetWeVoteEducationClick = async ( ) => {
191+ setEmailError ( '' ) ;
192+ const { emailOfficial, emailPersonal, firstName } = activePerson ;
193+ if ( ! emailOfficial . includes ( 'wevoteeducation.org' ) && ! emailPersonal . includes ( 'wevoteeducation.org' ) ) {
194+ setEmailError ( `"${ firstName } " does not have a wevoteeducation.org email as either their official (${ emailOfficial } ) or private (${ emailOfficial } ) address` ) ;
195+ return ;
196+ }
197+ const emailToChange = emailOfficial . includes ( 'wevoteeducation.org' ) ? emailOfficial : emailPersonal ;
191198 const newPassword = generateRandomString ( 12 ) ;
192- // console.log(`deletewevoteuserpassword ${primaryEmail } ${newPassword}`);
199+ // console.log(`deletewevoteuserpassword ${emailToChange } ${newPassword}`);
193200 const data = await weConnectQueryFn ( 'google-reset-user-password' , {
194- primaryEmail,
201+ primaryEmail : emailToChange ,
195202 newPassword,
196203 } , METHOD . POST ) ;
197204 // console.log('reset wevote password', data);
198205 if ( data . success ) {
199- setNewPasswordNotification ( `Thank you for requesting that your password be reset. These are your new sign in credentials: \n https://team.wevote.org \n user: ${ primaryEmail } \n pass: ${ newPassword } ` ) ;
206+ setNewPasswordNotification ( `Thank you for requesting that your password be reset. These are your new sign in credentials: \n https://team.wevote.org \n user: ${ emailToChange } \n pass: ${ newPassword } ` ) ;
200207 setShowNewPasswordNotification ( true ) ;
201208 } else {
202- console . error ( 'Failed to reset password:' , data ) ;
209+ // console.error('Failed to reset password:', data);
210+ console . log ( `Reset password API error: ${ data . error } ` ) ;
211+ if ( data . error . startsWith ( 'Missing required' ) ) {
212+ setEmailError ( `'${ emailToChange } ' is not an existing valid @wevoteeducation.org email address.` ) ;
213+ } else {
214+ setEmailError ( `${ data . error } , google api server code: ${ data . errorCode } ` ) ;
215+ }
203216 }
204217 } ;
205218
@@ -552,7 +565,7 @@ const EditPersonForm = ({ classes }) => {
552565 classes = { viewerIsOnHrTeam ? { root : classes . showThisField } : { root : classes . hideThisField } }
553566 disabled = { ! emailOfficialCanBeEdited }
554567 id = "emailOfficialToBeSaved"
555- label = { ` Email Address, $ {webAppConfig . ORGANIZATION_NAME } Official` }
568+ label = { < span style = { { paddingRight : '8px' } } > Email Address, { webAppConfig . ORGANIZATION_NAME } Official ( { webAppConfig . ORGANIZATION_NAME === 'WeVote' ? '@wevoteeducation.org' : '' } ) </ span > }
556569 margin = "dense"
557570 name = "emailOfficial"
558571 onChange = { ( event ) => {
@@ -565,9 +578,14 @@ const EditPersonForm = ({ classes }) => {
565578 value = { emailOfficialLocal }
566579 variant = "outlined"
567580 />
581+ { emailError . length > 0 && (
582+ < Alert icon = { < ErrorOutline fontSize = "inherit" /> } severity = "error" >
583+ { emailError }
584+ </ Alert >
585+ ) }
568586 < QuickLink >
569- < SpanWithLinkStyle onClick = { wevoteUserClick } >
570- Reset WeVote email password
587+ < SpanWithLinkStyle onClick = { resetWeVoteEducationClick } >
588+ Reset Official ( { webAppConfig . ORGANIZATION_NAME === ' WeVote' ? '@wevoteeducation.org' : '' } ) email password
571589 </ SpanWithLinkStyle >
572590 </ QuickLink >
573591 { showNewPasswordNotification && (
0 commit comments