Skip to content

Commit

Permalink
Merge pull request #53419 from layacat/fix/53177
Browse files Browse the repository at this point in the history
fix: 53177 Missing validate code sent when adding copilot
  • Loading branch information
thienlnam authored Dec 10, 2024
2 parents 709940e + 3b38c98 commit 8981081
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/libs/actions/Delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ function addDelegate(email: string, role: DelegateRole, validateCode: string) {
},
];

const optimisticResetActionCode = {
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.VALIDATE_ACTION_CODE,
value: {
validateCodeSent: null,
},
};
optimisticData.push(optimisticResetActionCode);

const parameters: AddDelegateParams = {delegateEmail: email, validateCode, role};

API.write(WRITE_COMMANDS.ADD_DELEGATE, parameters, {optimisticData, successData, failureData});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type DelegateMagicCodeModalProps = {
function DelegateMagicCodeModal({login, role, onClose, isValidateCodeActionModalVisible, shouldHandleNavigationBack}: DelegateMagicCodeModalProps) {
const {translate} = useLocalize();
const [account] = useOnyx(ONYXKEYS.ACCOUNT);

const [validateCodeAction] = useOnyx(ONYXKEYS.VALIDATE_ACTION_CODE);
const currentDelegate = account?.delegatedAccess?.delegates?.find((d) => d.email === login);
const addDelegateErrors = account?.delegatedAccess?.errorFields?.addDelegate?.[login];
const validateLoginError = ErrorUtils.getLatestError(addDelegateErrors);
Expand Down Expand Up @@ -56,7 +56,7 @@ function DelegateMagicCodeModal({login, role, onClose, isValidateCodeActionModal
isVisible={isValidateCodeActionModalVisible}
title={translate('delegate.makeSureItIsYou')}
sendValidateCode={() => User.requestValidateCodeAction()}
hasMagicCodeBeenSent={!!currentDelegate?.validateCodeSent}
hasMagicCodeBeenSent={validateCodeAction?.validateCodeSent}
handleSubmitForm={(validateCode) => Delegate.addDelegate(login, role, validateCode)}
descriptionPrimary={translate('delegate.enterMagicCode', {contactMethod: account?.primaryLogin ?? ''})}
/>
Expand Down

0 comments on commit 8981081

Please sign in to comment.