-
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
Chore/52820 workspace cards cleanup #52871
Changes from all commits
fd029a8
1cd6d19
2396fc0
d1b6ef5
47a9f12
6ee3551
824ad5b
d71e7f1
5c82d2c
d9dd7a3
4137f2f
2570632
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 |
---|---|---|
|
@@ -13,12 +13,16 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; | |
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as CardUtils from '@libs/CardUtils'; | ||
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; | ||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||
import Navigation from '@navigation/Navigation'; | ||
import variables from '@styles/variables'; | ||
import * as CompanyCards from '@userActions/CompanyCards'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {CompanyCardFeed} from '@src/types/onyx'; | ||
import type {AssignCardData, AssignCardStep} from '@src/types/onyx/AssignCard'; | ||
|
||
type WorkspaceCompanyCardsListHeaderButtonsProps = { | ||
/** Current policy id */ | ||
|
@@ -41,6 +45,36 @@ function WorkspaceCompanyCardsListHeaderButtons({policyID, selectedFeed}: Worksp | |
const isCustomFeed = CardUtils.isCustomFeed(selectedFeed); | ||
const companyFeeds = CardUtils.getCompanyFeeds(cardFeeds); | ||
const currentFeedData = companyFeeds?.[selectedFeed]; | ||
const policy = PolicyUtils.getPolicy(policyID); | ||
|
||
const [list] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${selectedFeed}`); | ||
const filteredCardList = CardUtils.getFilteredCardList(list); | ||
|
||
const handleAssignCard = () => { | ||
const data: Partial<AssignCardData> = { | ||
bankName: selectedFeed, | ||
}; | ||
|
||
let currentStep: AssignCardStep = CONST.COMPANY_CARD.STEP.ASSIGNEE; | ||
|
||
if (Object.keys(policy?.employeeList ?? {}).length === 1) { | ||
const userEmail = Object.keys(policy?.employeeList ?? {}).at(0) ?? ''; | ||
data.email = userEmail; | ||
const personalDetails = PersonalDetailsUtils.getPersonalDetailByEmail(userEmail); | ||
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. @koko57 NAB Let's create a util function to get card member name 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. It'll be done in my other PR #52735 - if it's a NAB here I will improve it in the other PR after this one is merged |
||
const memberName = personalDetails?.firstName ? personalDetails.firstName : personalDetails?.login; | ||
data.cardName = `${memberName}'s card`; | ||
currentStep = CONST.COMPANY_CARD.STEP.CARD; | ||
|
||
if (CardUtils.hasOnlyOneCardToAssign(filteredCardList)) { | ||
currentStep = CONST.COMPANY_CARD.STEP.TRANSACTION_START_DATE; | ||
data.cardNumber = Object.keys(filteredCardList).at(0); | ||
data.encryptedCardNumber = Object.values(filteredCardList).at(0); | ||
Comment on lines
+70
to
+71
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. @koko57 I believe that the two fields are different 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. what do you mean? 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. you have the key - "480801XXXXX2554" for the card name and the value "v11:47A..." for the encryptedCradNumber 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. @koko57 In your code change, you set two fields to the same value
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. Object.keys vs Object.values? how they are the same 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. I'm getting the first key "480801XXXXX2554" and it's value "v11:47A..." f 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. Sorry, my bad 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. It is fine |
||
} | ||
} | ||
|
||
CompanyCards.setAssignCardStepAndData({data, currentStep}); | ||
Navigation.setNavigationActionToMicrotaskQueue(() => Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS_ASSIGN_CARD.getRoute(policyID, selectedFeed))); | ||
}; | ||
|
||
return ( | ||
<OfflineWithFeedback | ||
|
@@ -79,7 +113,7 @@ function WorkspaceCompanyCardsListHeaderButtons({policyID, selectedFeed}: Worksp | |
<Button | ||
success | ||
isDisabled={!currentFeedData || !!currentFeedData?.pending || !!currentFeedData?.errors} | ||
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS_ASSIGN_CARD.getRoute(policyID, selectedFeed))} | ||
onPress={handleAssignCard} | ||
icon={Expensicons.Plus} | ||
text={translate('workspace.companyCards.assignCard')} | ||
style={shouldChangeLayout && styles.flex1} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; | |
import ROUTES from '@src/ROUTES'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type {CompanyCardFeed} from '@src/types/onyx'; | ||
import type {AssignCardData, AssignCardStep} from '@src/types/onyx/AssignCard'; | ||
|
||
type CardFeedListItem = ListItem & { | ||
/** Card feed value */ | ||
|
@@ -47,8 +48,12 @@ function WorkspaceMemberNewCardPage({route, personalDetails}: WorkspaceMemberNew | |
|
||
const accountID = Number(route.params.accountID); | ||
const memberLogin = personalDetails?.[accountID]?.login ?? ''; | ||
const memberName = personalDetails?.[accountID]?.firstName ? personalDetails?.[accountID]?.firstName : personalDetails?.[accountID]?.login; | ||
const availableCompanyCards = CardUtils.removeExpensifyCardFromCompanyCards(cardFeeds); | ||
|
||
const [list] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${selectedFeed}`); | ||
const filteredCardList = CardUtils.getFilteredCardList(list); | ||
|
||
const handleSubmit = () => { | ||
if (!selectedFeed) { | ||
setShouldShowError(true); | ||
|
@@ -64,14 +69,26 @@ function WorkspaceMemberNewCardPage({route, personalDetails}: WorkspaceMemberNew | |
}); | ||
Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW.getRoute(policyID, ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(policyID, accountID))); | ||
} else { | ||
const data: Partial<AssignCardData> = { | ||
email: memberLogin, | ||
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. NAB: Let's add bankName value 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. thanks, wouldn't say that is a NAB, I removed setting the feed in the assign card flow 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. @koko57 It is a NAB because we already saved feed on the route. But I think we still need to fix it 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. yeah, you're saving the feed on the route but not in the Onyx 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. @koko57 Let's add |
||
bankName: selectedFeed, | ||
cardName: `${memberName}'s card`, | ||
}; | ||
let currentStep: AssignCardStep = CONST.COMPANY_CARD.STEP.CARD; | ||
|
||
if (CardUtils.hasOnlyOneCardToAssign(filteredCardList)) { | ||
currentStep = CONST.COMPANY_CARD.STEP.TRANSACTION_START_DATE; | ||
data.cardNumber = Object.keys(filteredCardList).at(0); | ||
data.encryptedCardNumber = Object.values(filteredCardList).at(0); | ||
} | ||
CompanyCards.setAssignCardStepAndData({ | ||
currentStep: CONST.COMPANY_CARD.STEP.CARD, | ||
data: { | ||
email: memberLogin, | ||
}, | ||
currentStep, | ||
data, | ||
isEditing: false, | ||
}); | ||
Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS_ASSIGN_CARD.getRoute(policyID, selectedFeed, ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(policyID, accountID))); | ||
Navigation.setNavigationActionToMicrotaskQueue(() => | ||
Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS_ASSIGN_CARD.getRoute(policyID, selectedFeed, ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(policyID, accountID))), | ||
); | ||
} | ||
}; | ||
|
||
|
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.