-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: reuse ValidateCodeActionModal #49445
Changes from all commits
14ffa19
8b8046e
c1bac17
39f7823
b2aab12
af7f72c
201f533
0ea996a
92a43b5
0c52912
6349f44
592343f
49b9234
89970ef
7ee9659
b5695c4
f52d5a8
6bdd1bd
4d86852
5301e27
6ebcad9
1ec0b40
07ed2f2
ac5e8eb
74cc224
07b6501
c8db647
11741ab
35606ef
72a8705
063ff58
83bce36
30df3bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ type ValidateCodeFormProps = { | |
|
||
/** Function to clear error of the form */ | ||
clearError: () => void; | ||
|
||
sendValidateCode: () => void; | ||
}; | ||
|
||
function BaseValidateCodeForm({ | ||
|
@@ -73,6 +75,7 @@ function BaseValidateCodeForm({ | |
validateError, | ||
handleSubmitForm, | ||
clearError, | ||
sendValidateCode, | ||
buttonStyles, | ||
}: ValidateCodeFormProps) { | ||
const {translate} = useLocalize(); | ||
|
@@ -125,10 +128,6 @@ function BaseValidateCodeForm({ | |
}, []), | ||
); | ||
|
||
useEffect(() => { | ||
clearError(); | ||
}, [clearError]); | ||
|
||
useEffect(() => { | ||
if (!hasMagicCodeBeenSent) { | ||
return; | ||
|
@@ -140,7 +139,7 @@ function BaseValidateCodeForm({ | |
* Request a validate code / magic code be sent to verify this contact method | ||
*/ | ||
const resendValidateCode = () => { | ||
User.requestValidateCodeAction(); | ||
sendValidateCode(); | ||
inputValidateCodeRef.current?.clear(); | ||
}; | ||
|
||
|
@@ -189,7 +188,7 @@ function BaseValidateCodeForm({ | |
errorText={formError?.validateCode ? translate(formError?.validateCode) : ErrorUtils.getLatestErrorMessage(account ?? {})} | ||
hasError={!isEmptyObject(validateError)} | ||
onFulfill={validateAndSubmitForm} | ||
autoFocus={false} | ||
autoFocus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. We already discussed it during PR phase, but then forgot to update it here. |
||
/> | ||
<OfflineWithFeedback | ||
pendingAction={validateCodeAction?.pendingFields?.validateCodeSent} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,14 +6,26 @@ import Modal from '@components/Modal'; | |||||||||||||
import ScreenWrapper from '@components/ScreenWrapper'; | ||||||||||||||
import Text from '@components/Text'; | ||||||||||||||
import useThemeStyles from '@hooks/useThemeStyles'; | ||||||||||||||
import * as User from '@libs/actions/User'; | ||||||||||||||
import CONST from '@src/CONST'; | ||||||||||||||
import ONYXKEYS from '@src/ONYXKEYS'; | ||||||||||||||
import type {ValidateCodeActionModalProps} from './type'; | ||||||||||||||
import ValidateCodeForm from './ValidateCodeForm'; | ||||||||||||||
import type {ValidateCodeFormHandle} from './ValidateCodeForm/BaseValidateCodeForm'; | ||||||||||||||
|
||||||||||||||
function ValidateCodeActionModal({isVisible, title, description, onClose, validatePendingAction, validateError, handleSubmitForm, clearError}: ValidateCodeActionModalProps) { | ||||||||||||||
function ValidateCodeActionModal({ | ||||||||||||||
isVisible, | ||||||||||||||
title, | ||||||||||||||
description, | ||||||||||||||
onClose, | ||||||||||||||
onModalHide, | ||||||||||||||
validatePendingAction, | ||||||||||||||
validateError, | ||||||||||||||
handleSubmitForm, | ||||||||||||||
clearError, | ||||||||||||||
footer, | ||||||||||||||
sendValidateCode, | ||||||||||||||
hasMagicCodeBeenSent, | ||||||||||||||
}: ValidateCodeActionModalProps) { | ||||||||||||||
const themeStyles = useThemeStyles(); | ||||||||||||||
const firstRenderRef = useRef(true); | ||||||||||||||
const validateCodeFormRef = useRef<ValidateCodeFormHandle>(null); | ||||||||||||||
|
@@ -30,15 +42,16 @@ function ValidateCodeActionModal({isVisible, title, description, onClose, valida | |||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
firstRenderRef.current = false; | ||||||||||||||
User.requestValidateCodeAction(); | ||||||||||||||
}, [isVisible]); | ||||||||||||||
|
||||||||||||||
sendValidateCode(); | ||||||||||||||
}, [isVisible, sendValidateCode]); | ||||||||||||||
|
||||||||||||||
return ( | ||||||||||||||
<Modal | ||||||||||||||
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED} | ||||||||||||||
isVisible={isVisible} | ||||||||||||||
onClose={hide} | ||||||||||||||
onModalHide={hide} | ||||||||||||||
onModalHide={onModalHide ?? hide} | ||||||||||||||
hideModalContentWhileAnimating | ||||||||||||||
useNativeDriver | ||||||||||||||
shouldUseModalPaddingStyle={false} | ||||||||||||||
|
@@ -61,10 +74,13 @@ function ValidateCodeActionModal({isVisible, title, description, onClose, valida | |||||||||||||
validatePendingAction={validatePendingAction} | ||||||||||||||
validateError={validateError} | ||||||||||||||
handleSubmitForm={handleSubmitForm} | ||||||||||||||
sendValidateCode={sendValidateCode} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason why we made this a prop instead of implementing it in this component? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
App/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx Lines 141 to 143 in 44c9260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, so why isn't the implementation of sendValidateCode is not in ValidateCodeActionModal here
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically this code is repeated in every component that uses this modal
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two functions to request a magic code requestContactMethodValidateCode & requestValidateCodeAction And there may be conditions before calling the function, which means if we want to implement App/src/pages/settings/Wallet/ExpensifyCardPage.tsx Lines 150 to 151 in 9508b17
I thought this would be the most convenient way to make the component flexible. |
||||||||||||||
clearError={clearError} | ||||||||||||||
ref={validateCodeFormRef} | ||||||||||||||
hasMagicCodeBeenSent={hasMagicCodeBeenSent} | ||||||||||||||
/> | ||||||||||||||
</View> | ||||||||||||||
{footer?.()} | ||||||||||||||
</ScreenWrapper> | ||||||||||||||
</Modal> | ||||||||||||||
); | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs