-
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
fix navigation for different assignees in confirmation flow #56732
base: main
Are you sure you want to change the base?
Conversation
@s77rt , I can only test with mocking the data, can you test with some real data please ? |
const parts = backTo?.split('/'); | ||
const membersIndex = parts?.indexOf('members') ?? -1; | ||
const workspaceMemberAccountID = parts?.[membersIndex + 1] ?? ''; |
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.
This is a hacky solution. We don't want to assume that the string members
is always followed by. the account id. Can we instead extract the account id from assignCard?.data
first value?
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.
okay, I will try that today and update back, thanks for the feedback
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.
Can we instead extract the account id from assignCard?.data first value?
@s77rt we get the assignCard?.data
email value for cardholderAccountID
, already, and it will keep changing everytime the assingee will change, so i guess our option is to extract the account ID from the URL itself, I will still think through this one, but let me know if you have any idea around this
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.
I meant to use the first valid value from assignCard?.data
. You can try use useRef
or usePrevious
hooks.
PS: Only store the first valid value i.e. check that assignedData
is not undefined
(e.g. onyx data is not loaded yet)
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.
yeah, usePrevious
was the first thing that came in my mind, thanks for the input, I will try implementing it and report back!
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.
@s77rt how about we add a new prop to AssignCardData
:
App/src/types/onyx/AssignCard.ts
Lines 8 to 10 in 6d5c89f
type AssignCardData = { | |
/** The email address of the assignee */ | |
email: string; |
As workspaceMemberEmail
, so everytime in WorkspaceMemberNewCardPage
, when we set initial data below:
App/src/pages/workspace/members/WorkspaceMemberNewCardPage.tsx
Lines 73 to 76 in 6d5c89f
} else { | |
const data: Partial<AssignCardData> = { | |
email: memberLogin, | |
bankName: selectedFeed, |
We set this value and later compare this value with cardholder email ? , what do you think of this approach
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.
Let's not do that as that info is not part of the card data
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.
Can we instead pass an extra param to the WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW route and use it for comparison with the selected account id
the routes will only take backTo as an extra param by using getUrlWithBackToParam
:
Lines 17 to 20 in edef703
function getUrlWithBackToParam<TUrl extends string>(url: TUrl, backTo?: string, shouldEncodeURIComponent = true): `${TUrl}` { | |
const backToParam = backTo ? (`${url.includes('?') ? '&' : '?'}backTo=${shouldEncodeURIComponent ? encodeURIComponent(backTo) : backTo}` as const) : ''; | |
return `${url}${backToParam}` as `${TUrl}`; | |
} |
So i guess for this one we would need to build a new similar function which would work for the company cards redirection route, currently it used getUrlWithBackToParam
, should i proceed with this approach ?
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.
No need for a new function. You can add the param before calling getUrlWithBackToParam
. Please refer to SETTINGS_2FA
or SETTINGS_EXIT_SURVEY_RESPONSE
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.
Oh sorry i misunderstood what you meant here, yeah, it is a lot more reliable to follow the approach you suggested, updating the code now
Also please merge main to take into account the new navigation refactor |
@s77rt done with merging, I'll update the requested change today |
const workspaceMemberAccountID = getPersonalDetailByEmail(firstValidEmail ?? '')?.accountID?.toString() ?? ''; | ||
const cardholderAccountID = getPersonalDetailByEmail(data?.email ?? '')?.accountID?.toString() ?? ''; |
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.
@s77rt last question, I think we should directly compare numerical values here instead of converting it to a string, it saves extra compute, what do you think ?
src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx
Outdated
Show resolved
Hide resolved
@@ -27,10 +27,17 @@ function AssignCardFeedPage({route, policy}: AssignCardFeedPageProps) { | |||
const backTo = route.params?.backTo; | |||
const policyID = policy?.id; | |||
const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.delegatedAccess?.delegate}); | |||
const [firstValidEmail, setFirstValidEmail] = useState<string | null>(null); | |||
useEffect(() => { | |||
if (firstValidEmail || !assignCard?.data?.email) { |
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.
@s77rt should we disable this error ?, in useState i can initialise the value to empty string and then silence the error here, what do you think ?
src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx
Outdated
Show resolved
Hide resolved
<ConfirmationStep | ||
policyID={policyID} | ||
backTo={backTo} | ||
workspaceMemberAccountID={workspaceMemberAccountID} | ||
/> |
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.
I missed that we pass route params here. In that case we shouldn't use the current approach as we are still passing through AssignCardFeedPage
. Instead we should store the first valid assignee email and compare it with the current one and if they are not the same let's not pass the backTo param. Something like this:
const firstAssigneeEmail = useRef(issueNewCard?.data.assigneeEmail);
if (!firstAssigneeEmail.current) {
firstAssigneeEmail.current = issueNewCard?.data.assigneeEmail;
}
const shouldUseBackToParam = !firstAssigneeEmail.current || firstAssigneeEmail.current === issueNewCard?.data.assigneeEmail;
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.
@s77rt I tried this one and Confirmation
page re-renders each time clearing the firstAssigneeEmail
ref, we had to pass it via AssignCardFeedPage
only for the value of the ref to persist, you can take a look at 867522c commit of the previous implementation.
Its late for me now, but i will again try to take a look at this tomorrow morning, thanks
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.
That code should go in AssignCardFeedPage
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.
Alright!, I am OoO for today, I will update this PR tomorrow morning, thanks for the patience
Explanation of Change
This PR fixes the navigation logic for company cards page, whenever a card is assigned from the workspace members profile page but we select a different member on the confirmation screen, we now redirect to the company cards page than workspace member details page.
Fixed Issues
$ #56009
PROPOSAL: #56009 (comment)
Tests
Same as QA
Offline tests
Cannot test offline
QA Steps
Precondition: workspace with several members, with enabled Company cards. Some company cards are added.
Verify that: User lands to Company cards page, rather than the workspace member profile he was previously on (as you assigned the card to someone else)
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop