Skip to content

Commit

Permalink
Merge pull request #48184 from software-mansion-labs/Guccio/47019-Tag…
Browse files Browse the repository at this point in the history
…SettingsBillable

Tag settings: Billable #47019
  • Loading branch information
marcaaron authored Sep 3, 2024
2 parents 77beaa2 + bb30c66 commit 227aa13
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 116 deletions.
3 changes: 2 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2972,7 +2972,7 @@ export default {
},
tags: {
title: 'Tags',
subtitle: 'Add additional ways to classify spend.',
subtitle: 'Classify costs and track billable expenses.',
},
taxes: {
title: 'Taxes',
Expand Down Expand Up @@ -3048,6 +3048,7 @@ export default {
tags: {
tagName: 'Tag name',
requiresTag: 'Members must tag all expenses',
trackBillable: 'Track billable expenses',
customTagName: 'Custom tag name',
enableTag: 'Enable tag',
enableTags: 'Enable tags',
Expand Down
3 changes: 2 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3023,7 +3023,7 @@ export default {
},
tags: {
title: 'Etiquetas',
subtitle: 'Añade formas adicionales de clasificar los gastos.',
subtitle: 'Clasifica costes y rastrea gastos facturables.',
},
taxes: {
title: 'Impuestos',
Expand Down Expand Up @@ -3099,6 +3099,7 @@ export default {
tags: {
tagName: 'Nombre de etiqueta',
requiresTag: 'Los miembros deben etiquetar todos los gastos',
trackBillable: 'Permitir marcar gastos como facturables',
customTagName: 'Nombre de etiqueta personalizada',
enableTag: 'Habilitar etiqueta',
enableTags: 'Habilitar etiquetas',
Expand Down
5 changes: 5 additions & 0 deletions src/libs/API/parameters/DisablePolicyBillableModeParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type DisablePolicyBillableModeParams = {
policyID: string;
};

export default DisablePolicyBillableModeParams;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type SetPolicyBillableMode = {
type SetPolicyBillableModeParams = {
policyID: string;
defaultBillable: boolean;
/**
* Stringified JSON object with type of following structure:
Expand All @@ -9,4 +10,4 @@ type SetPolicyBillableMode = {
disabledFields: string;
};

export default SetPolicyBillableMode;
export default SetPolicyBillableModeParams;
3 changes: 2 additions & 1 deletion src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ export type {default as SetPolicyRulesEnabledParams} from './SetPolicyRulesEnabl
export type {default as SetPolicyExpenseMaxAmountNoReceipt} from './SetPolicyExpenseMaxAmountNoReceipt';
export type {default as SetPolicyExpenseMaxAmount} from './SetPolicyExpenseMaxAmount';
export type {default as SetPolicyExpenseMaxAge} from './SetPolicyExpenseMaxAge';
export type {default as SetPolicyBillableMode} from './SetPolicyBillableMode';
export type {default as SetPolicyBillableModeParams} from './SetPolicyBillableModeParams';
export type {default as DisablePolicyBillableModeParams} from './DisablePolicyBillableModeParams';
export type {default as SetWorkspaceEReceiptsEnabled} from './SetWorkspaceEReceiptsEnabled';
export type {default as ConfigureExpensifyCardsForPolicyParams} from './ConfigureExpensifyCardsForPolicyParams';
export type {default as CreateExpensifyCardParams} from './CreateExpensifyCardParams';
Expand Down
4 changes: 3 additions & 1 deletion src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ const WRITE_COMMANDS = {
SET_POLICY_EXPENSE_MAX_AMOUNT: 'SetPolicyExpenseMaxAmount',
SET_POLICY_EXPENSE_MAX_AGE: ' SetPolicyExpenseMaxAge',
SET_POLICY_BILLABLE_MODE: ' SetPolicyBillableMode',
DISABLE_POLICY_BILLABLE_MODE: 'DisablePolicyBillableExpenses',
SET_WORKSPACE_ERECEIPTS_ENABLED: 'SetWorkspaceEReceiptsEnabled',
SET_POLICY_TAXES_CURRENCY_DEFAULT: 'SetPolicyCurrencyDefaultTax',
SET_POLICY_TAXES_FOREIGN_CURRENCY_DEFAULT: 'SetPolicyForeignCurrencyDefaultTax',
Expand Down Expand Up @@ -589,7 +590,8 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.SET_POLICY_EXPENSE_MAX_AMOUNT_NO_RECEIPT]: Parameters.SetPolicyExpenseMaxAmountNoReceipt;
[WRITE_COMMANDS.SET_POLICY_EXPENSE_MAX_AMOUNT]: Parameters.SetPolicyExpenseMaxAmount;
[WRITE_COMMANDS.SET_POLICY_EXPENSE_MAX_AGE]: Parameters.SetPolicyExpenseMaxAge;
[WRITE_COMMANDS.SET_POLICY_BILLABLE_MODE]: Parameters.SetPolicyBillableMode;
[WRITE_COMMANDS.SET_POLICY_BILLABLE_MODE]: Parameters.SetPolicyBillableModeParams;
[WRITE_COMMANDS.DISABLE_POLICY_BILLABLE_MODE]: Parameters.DisablePolicyBillableModeParams;
[WRITE_COMMANDS.SET_WORKSPACE_ERECEIPTS_ENABLED]: Parameters.SetWorkspaceEReceiptsEnabled;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR]: Parameters.UpdateQuickbooksOnlineAutoCreateVendorParams;
Expand Down
62 changes: 60 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
CreateWorkspaceParams,
DeleteWorkspaceAvatarParams,
DeleteWorkspaceParams,
DisablePolicyBillableModeParams,
EnablePolicyCompanyCardsParams,
EnablePolicyConnectionsParams,
EnablePolicyExpensifyCardsParams,
Expand All @@ -32,6 +33,7 @@ import type {
OpenWorkspaceParams,
OpenWorkspaceReimburseViewParams,
RequestExpensifyCardLimitIncreaseParams,
SetPolicyBillableModeParams,
SetWorkspaceApprovalModeParams,
SetWorkspaceAutoReportingFrequencyParams,
SetWorkspaceAutoReportingMonthlyOffsetParams,
Expand Down Expand Up @@ -3645,6 +3647,7 @@ function setPolicyBillableMode(policyID: string, defaultBillable: boolean) {
},
pendingFields: {
defaultBillable: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
disabledFields: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
Expand All @@ -3656,6 +3659,7 @@ function setPolicyBillableMode(policyID: string, defaultBillable: boolean) {
value: {
pendingFields: {
defaultBillable: null,
disabledFields: null,
},
errorFields: null,
},
Expand All @@ -3668,14 +3672,14 @@ function setPolicyBillableMode(policyID: string, defaultBillable: boolean) {
value: {
disabledFields: {defaultBillable: originalDefaultBillableDisabled},
defaultBillable: originalDefaultBillable,
pendingFields: {defaultBillable: null},
pendingFields: {defaultBillable: null, disabledFields: null},
errorFields: {defaultBillable: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')},
},
},
],
};

const parameters = {
const parameters: SetPolicyBillableModeParams = {
policyID,
defaultBillable,
disabledFields: JSON.stringify({
Expand All @@ -3686,6 +3690,59 @@ function setPolicyBillableMode(policyID: string, defaultBillable: boolean) {
API.write(WRITE_COMMANDS.SET_POLICY_BILLABLE_MODE, parameters, onyxData);
}

/**
* Call the API to disable the billable mode for the given policy
* @param policyID - id of the policy to enable or disable the bilable mode
*/
function disableWorkspaceBillableExpenses(policyID: string) {
const policy = getPolicy(policyID);
const originalDefaultBillableDisabled = policy?.disabledFields?.defaultBillable;

const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
disabledFields: {
defaultBillable: true,
},
pendingFields: {
disabledFields: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {
disabledFields: null,
},
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {disabledFields: null},
disabledFields: {defaultBillable: originalDefaultBillableDisabled},
},
},
],
};

const parameters: DisablePolicyBillableModeParams = {
policyID,
};

API.write(WRITE_COMMANDS.DISABLE_POLICY_BILLABLE_MODE, parameters, onyxData);
}

function setWorkspaceEReceiptsEnabled(policyID: string, eReceipts: boolean) {
const policy = getPolicy(policyID);

Expand Down Expand Up @@ -3914,6 +3971,7 @@ export {
setPolicyMaxExpenseAmount,
setPolicyMaxExpenseAge,
setPolicyBillableMode,
disableWorkspaceBillableExpenses,
setWorkspaceEReceiptsEnabled,
setWorkspaceCompanyCardFeedName,
deleteWorkspaceCompanyCardFeed,
Expand Down
82 changes: 0 additions & 82 deletions src/pages/Search/AdvancedSearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,88 +243,6 @@ function AdvancedSearchFilters() {
const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);
const taxRates = getAllTaxRates();
const personalDetails = usePersonalDetails();

// const advancedFilters = useMemo(
// () => [
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.DATE, translate),
// description: 'common.date' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_DATE,
// },
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY, translate),
// description: 'common.currency' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_CURRENCY,
// },
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.MERCHANT, translate),
// description: 'common.merchant' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_MERCHANT,
// },
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.DESCRIPTION, translate),
// description: 'common.description' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_DESCRIPTION,
// },
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_ID, translate),
// description: 'common.reportID' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_REPORT_ID,
// },
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.AMOUNT, translate),
// description: 'common.total' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_AMOUNT,
// },
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, translate),
// description: 'common.category' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_CATEGORY,
// },
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.KEYWORD, translate),
// description: 'search.filters.hasKeywords' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_KEYWORD,
// },
// {
// title: getFilterCardDisplayTitle(searchAdvancedFilters, cardList),
// description: 'common.card' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_CARD,
// shouldHide: Object.keys(cardList).length === 0,
// },
// {
// title: getFilterTaxRateDisplayTitle(searchAdvancedFilters, taxRates),
// description: 'workspace.taxes.taxRate' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_TAX_RATE,
// },
// {
// title: getFilterExpenseDisplayTitle(searchAdvancedFilters, translate),
// description: 'search.expenseType' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_EXPENSE_TYPE,
// },
// {
// title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG, translate),
// description: 'common.tag' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_TAG,
// },
// {
// title: getFilterParticipantDisplayTitle(searchAdvancedFilters.from ?? [], personalDetails),
// description: 'common.from' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_FROM,
// },
// {
// title: getFilterParticipantDisplayTitle(searchAdvancedFilters.to ?? [], personalDetails),
// description: 'common.to' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_TO,
// },
// {
// title: getFilterInDisplayTitle(searchAdvancedFilters, translate, reports),
// description: 'common.in' as const,
// route: ROUTES.SEARCH_ADVANCED_FILTERS_IN,
// },
// ],
// [searchAdvancedFilters, translate, cardList, taxRates, personalDetails, reports],
// );
const currentType = searchAdvancedFilters?.type ?? CONST.SEARCH.DATA_TYPES.EXPENSE;

const onFormSubmit = () => {
Expand Down
18 changes: 9 additions & 9 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc
});
}

if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED] && canUseWorkspaceRules) {
protectedCollectPolicyMenuItems.push({
translationKey: 'workspace.common.rules',
icon: Expensicons.Feed,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_RULES.getRoute(policyID)))),
routeName: SCREENS.WORKSPACE.RULES,
});
}

if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED]) {
protectedCollectPolicyMenuItems.push({
translationKey: 'workspace.common.categories',
Expand Down Expand Up @@ -314,15 +323,6 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc
});
}

if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED] && canUseWorkspaceRules) {
protectedCollectPolicyMenuItems.push({
translationKey: 'workspace.common.rules',
icon: Expensicons.Feed,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_RULES.getRoute(policyID)))),
routeName: SCREENS.WORKSPACE.RULES,
});
}

protectedCollectPolicyMenuItems.push({
translationKey: 'workspace.common.moreFeatures',
icon: Expensicons.Gear,
Expand Down
Loading

0 comments on commit 227aa13

Please sign in to comment.