-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Feature: Integrate OpenPolicyEditCardLimitTypePage api command to the app #47092
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
Changes from all commits
497e3c4
c8183fd
ab8b4f2
7882274
e3e503c
eca5d5d
abe1080
c88d210
68b4ac5
ce7422e
7932553
18e344d
e927072
f0de767
0881a50
dc1897e
6aab7e4
2145f46
8819dd3
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type OpenPolicyEditCardLimitTypePageParams = { | ||
policyID: string; | ||
authToken: string | null | undefined; | ||
cardID: number; | ||
}; | ||
|
||
export default OpenPolicyEditCardLimitTypePageParams; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import {useFocusEffect} from '@react-navigation/native'; | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React, {useMemo, useState} from 'react'; | ||
import React, {useCallback, useMemo, useState} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; | ||
import Button from '@components/Button'; | ||
import ConfirmModal from '@components/ConfirmModal'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
|
@@ -15,6 +17,7 @@ import * as PolicyUtils from '@libs/PolicyUtils'; | |
import Navigation from '@navigation/Navigation'; | ||
import type {SettingsNavigatorParamList} from '@navigation/types'; | ||
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; | ||
import * as Policy from '@userActions/Policy/Policy'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
@@ -38,20 +41,43 @@ function WorkspaceEditCardLimitTypePage({route}: WorkspaceEditCardLimitTypePageP | |
const defaultLimitType = areApprovalsConfigured ? CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART : CONST.EXPENSIFY_CARD.LIMIT_TYPES.MONTHLY; | ||
const initialLimitType = card?.nameValuePairs?.limitType ?? defaultLimitType; | ||
const promptTranslationKey = | ||
initialLimitType === CONST.EXPENSIFY_CARD.LIMIT_TYPES.MONTHLY | ||
? 'workspace.expensifyCard.changeCardMonthlyLimitTypeWarning' | ||
: 'workspace.expensifyCard.changeCardSmartLimitTypeWarning'; | ||
initialLimitType === CONST.EXPENSIFY_CARD.LIMIT_TYPES.MONTHLY || initialLimitType === CONST.EXPENSIFY_CARD.LIMIT_TYPES.FIXED | ||
? 'workspace.expensifyCard.changeCardSmartLimitTypeWarning' | ||
: 'workspace.expensifyCard.changeCardMonthlyLimitTypeWarning'; | ||
|
||
const [typeSelected, setTypeSelected] = useState(initialLimitType); | ||
const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); | ||
|
||
const fetchCardLimitTypeData = useCallback(() => { | ||
Policy.openPolicyEditCardLimitTypePage(policyID, Number(cardID)); | ||
}, [policyID, cardID]); | ||
|
||
useFocusEffect(fetchCardLimitTypeData); | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const updateCardLimitType = () => { | ||
// TODO: add API call when it's supported https://github.com/Expensify/Expensify/issues/407833 | ||
}; | ||
|
||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const submit = () => { | ||
// TODO: update the condition of showing confirm warning when requirements are known | ||
const shouldShowConfirmModal = true; | ||
let shouldShowConfirmModal = false; | ||
if (!!card?.unapprovedSpend && card?.nameValuePairs?.unapprovedExpenseLimit) { | ||
// Spends are coming as negative numbers from the backend and we need to make it positive for the correct expression. | ||
const unapprovedSpend = Math.abs(card.unapprovedSpend); | ||
const isUnapprovedSpendOverLimit = unapprovedSpend >= card.nameValuePairs.unapprovedExpenseLimit; | ||
|
||
const validCombinations = [ | ||
[CONST.EXPENSIFY_CARD.LIMIT_TYPES.MONTHLY, CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART], | ||
[CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART, CONST.EXPENSIFY_CARD.LIMIT_TYPES.MONTHLY], | ||
[CONST.EXPENSIFY_CARD.LIMIT_TYPES.FIXED, CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART], | ||
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. We could also be updating a fixed limit card to monthly? 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. So Fixed -> Monthly should be included in validCombinations, correct? 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. According to the docs, Yes! 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. Cool, @waterim could you update this? :) 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. They are OoO until monday :) 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. Ah, okay, I've just pushed a commit to add this |
||
[CONST.EXPENSIFY_CARD.LIMIT_TYPES.FIXED, CONST.EXPENSIFY_CARD.LIMIT_TYPES.MONTHLY], | ||
]; | ||
// Check if the combination exists in validCombinations | ||
const isValidCombination = validCombinations.some(([limitType, selectedType]) => initialLimitType === limitType && typeSelected === selectedType); | ||
|
||
if (isValidCombination && isUnapprovedSpendOverLimit) { | ||
shouldShowConfirmModal = true; | ||
} | ||
} | ||
|
||
if (shouldShowConfirmModal) { | ||
setIsConfirmModalVisible(true); | ||
|
@@ -62,8 +88,17 @@ function WorkspaceEditCardLimitTypePage({route}: WorkspaceEditCardLimitTypePageP | |
|
||
const data = useMemo(() => { | ||
const options = []; | ||
// TODO: update the condition of showing the fixed option when requirements are known | ||
const shouldShowFixedOption = true; | ||
let shouldShowFixedOption = true; | ||
|
||
if (card?.totalSpend && card?.nameValuePairs?.unapprovedExpenseLimit) { | ||
const totalSpend = Math.abs(card.totalSpend); | ||
if ( | ||
(initialLimitType === CONST.EXPENSIFY_CARD.LIMIT_TYPES.MONTHLY || initialLimitType === CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART) && | ||
totalSpend >= card.nameValuePairs?.unapprovedExpenseLimit | ||
) { | ||
shouldShowFixedOption = false; | ||
} | ||
} | ||
|
||
if (areApprovalsConfigured) { | ||
options.push({ | ||
|
@@ -96,7 +131,7 @@ function WorkspaceEditCardLimitTypePage({route}: WorkspaceEditCardLimitTypePageP | |
} | ||
|
||
return options; | ||
}, [translate, typeSelected, areApprovalsConfigured]); | ||
}, [areApprovalsConfigured, card, initialLimitType, translate, typeSelected]); | ||
|
||
return ( | ||
<AccessOrNotFoundWrapper | ||
|
@@ -113,34 +148,35 @@ function WorkspaceEditCardLimitTypePage({route}: WorkspaceEditCardLimitTypePageP | |
title={translate('workspace.card.issueNewCard.limitType')} | ||
onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_EXPENSIFY_CARD_DETAILS.getRoute(policyID, cardID))} | ||
/> | ||
<SelectionList | ||
ListItem={RadioListItem} | ||
onSelectRow={({value}) => setTypeSelected(value)} | ||
sections={[{data}]} | ||
shouldUpdateFocusedIndex | ||
shouldSingleExecuteRowSelect | ||
isAlternateTextMultilineSupported | ||
initiallyFocusedOptionKey={typeSelected} | ||
/> | ||
<ConfirmModal | ||
title={translate('workspace.expensifyCard.changeCardLimitType')} | ||
isVisible={isConfirmModalVisible} | ||
onConfirm={updateCardLimitType} | ||
onCancel={() => setIsConfirmModalVisible(false)} | ||
prompt={translate(promptTranslationKey, CurrencyUtils.convertToDisplayString(card?.nameValuePairs?.unapprovedExpenseLimit, CONST.CURRENCY.USD))} | ||
confirmText={translate('workspace.expensifyCard.changeLimitType')} | ||
cancelText={translate('common.cancel')} | ||
danger | ||
shouldEnableNewFocusManagement | ||
/> | ||
<Button | ||
success | ||
large | ||
pressOnEnter | ||
text={translate('common.save')} | ||
onPress={submit} | ||
style={styles.m5} | ||
/> | ||
<FullPageOfflineBlockingView> | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<SelectionList | ||
ListItem={RadioListItem} | ||
onSelectRow={({value}) => setTypeSelected(value)} | ||
sections={[{data}]} | ||
shouldUpdateFocusedIndex | ||
isAlternateTextMultilineSupported | ||
initiallyFocusedOptionKey={typeSelected} | ||
/> | ||
<ConfirmModal | ||
title={translate('workspace.expensifyCard.changeCardLimitType')} | ||
isVisible={isConfirmModalVisible} | ||
onConfirm={updateCardLimitType} | ||
onCancel={() => setIsConfirmModalVisible(false)} | ||
prompt={translate(promptTranslationKey, CurrencyUtils.convertToDisplayString(card?.nameValuePairs?.unapprovedExpenseLimit, CONST.CURRENCY.USD))} | ||
confirmText={translate('workspace.expensifyCard.changeLimitType')} | ||
cancelText={translate('common.cancel')} | ||
danger | ||
shouldEnableNewFocusManagement | ||
/> | ||
<Button | ||
success | ||
large | ||
pressOnEnter | ||
text={translate('common.save')} | ||
onPress={submit} | ||
style={styles.m5} | ||
/> | ||
</FullPageOfflineBlockingView> | ||
</ScreenWrapper> | ||
</AccessOrNotFoundWrapper> | ||
); | ||
|
Uh oh!
There was an error while loading. Please reload this page.