Skip to content
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

[OldDot Rules Migration] Add "Rules" Row/toggle to "More Features" page #47083

Merged
merged 24 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4394c62
Add Manage section to More Features Page and button to enable Rules
WojtekBoman Aug 7, 2024
8dcdd0c
Handle SetPolicyRulesEnabled
WojtekBoman Aug 7, 2024
d106bdb
Add PolicyRulesPage
WojtekBoman Aug 8, 2024
f739ff4
Update policyFeatureStates
WojtekBoman Aug 8, 2024
5473fc3
Merge branch 'main' into rules/toggle
WojtekBoman Aug 12, 2024
74269b2
Add new const GUIDES_CALL_TASK_IDS.WORKSPACE_RULES
WojtekBoman Aug 12, 2024
74fe492
Merge branch 'main' into rules/toggle
WojtekBoman Aug 13, 2024
00b4cfa
Fix rules svg structure
WojtekBoman Aug 13, 2024
954cf58
Add translations for rules section
WojtekBoman Aug 13, 2024
af6227a
Add missing rules translation
WojtekBoman Aug 13, 2024
02ae07b
Merge branch 'main' into rules/toggle
WojtekBoman Aug 14, 2024
9f237c2
Cleanup policy rules code
WojtekBoman Aug 14, 2024
068f9a6
Fix displaying rules menu item in WorkspaceInitialPage
WojtekBoman Aug 14, 2024
b70d783
Rename default policy rules values
WojtekBoman Aug 14, 2024
d886ef5
Fix redirecting after enabling rules
WojtekBoman Aug 14, 2024
3d9e73a
Merge branch 'main' into rules/toggle
WojtekBoman Aug 19, 2024
f46888e
Replace rules EMPTY_ consts with DISABLED_MAX_EXPENSE_VALUE
WojtekBoman Aug 19, 2024
c525d10
Add links to individual expense rules section
WojtekBoman Aug 19, 2024
3f574fb
Remove unnecessary check from toggling Rules in More Features
WojtekBoman Aug 19, 2024
4b24592
Remove empty space from API/types
WojtekBoman Aug 19, 2024
79f5b7c
Add rules beta and hide toggling this feature and rules page
WojtekBoman Aug 19, 2024
2bdd769
Rename rules beta to workspaceRules
WojtekBoman Aug 20, 2024
1fd206a
Fix es rules translations
WojtekBoman Aug 20, 2024
8970dd4
Fix name in rules beta permission method
WojtekBoman Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/images/feed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const CONST = {
DEFAULT_TABLE_NAME: 'keyvaluepairs',
DEFAULT_ONYX_DUMP_FILE_NAME: 'onyx-state.txt',
DEFAULT_POLICY_ROOM_CHAT_TYPES: [chatTypes.POLICY_ADMINS, chatTypes.POLICY_ANNOUNCE, chatTypes.DOMAIN_ALL],
DISABLED_MAX_EXPENSE_VALUE: 10000000000,

// Note: Group and Self-DM excluded as these are not tied to a Workspace
WORKSPACE_ROOM_TYPES: [chatTypes.POLICY_ADMINS, chatTypes.POLICY_ANNOUNCE, chatTypes.DOMAIN_ALL, chatTypes.POLICY_ROOM, chatTypes.POLICY_EXPENSE_CHAT],
Expand Down Expand Up @@ -381,6 +382,7 @@ const CONST = {
REPORT_FIELDS_FEATURE: 'reportFieldsFeature',
WORKSPACE_FEEDS: 'workspaceFeeds',
NETSUITE_USA_TAX: 'netsuiteUsaTax',
RULES: 'rules',
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
},
BUTTON_STATES: {
DEFAULT: 'default',
Expand Down Expand Up @@ -2082,6 +2084,7 @@ const CONST = {
ARE_EXPENSIFY_CARDS_ENABLED: 'areExpensifyCardsEnabled',
ARE_INVOICES_ENABLED: 'areInvoicesEnabled',
ARE_TAXES_ENABLED: 'tax',
ARE_RULES_ENABLED: 'areRulesEnabled',
},
DEFAULT_CATEGORIES: [
'Advertising',
Expand Down Expand Up @@ -2415,6 +2418,7 @@ const CONST = {
WORKSPACE_BANK_ACCOUNT: 'WorkspaceBankAccount',
WORKSPACE_SETTINGS: 'WorkspaceSettings',
WORKSPACE_FEATURES: 'WorkspaceFeatures',
WORKSPACE_RULES: 'WorkspaceRules',
},
get EXPENSIFY_EMAILS() {
return [
Expand Down Expand Up @@ -5461,6 +5465,14 @@ const CONST = {
description: 'workspace.upgrade.taxCodes.description' as const,
icon: 'Coins',
},
rules: {
id: 'rules' as const,
alias: 'rules',
name: 'Rules',
title: 'workspace.upgrade.rules.title' as const,
description: 'workspace.upgrade.rules.description' as const,
WojtekBoman marked this conversation as resolved.
Show resolved Hide resolved
icon: 'Rules',
},
};
},
REPORT_FIELD_TYPES: {
Expand Down
4 changes: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,10 @@ const ROUTES = {
route: 'settings/workspaces/:policyID/expensify-card/settings/frequency',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/expensify-card/settings/frequency` as const,
},
WORKSPACE_RULES: {
route: 'settings/workspaces/:policyID/rules',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/rules` as const,
},
WORKSPACE_DISTANCE_RATES: {
route: 'settings/workspaces/:policyID/distance-rates',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/distance-rates` as const,
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ const SCREENS = {
DISTANCE_RATE_TAX_RECLAIMABLE_ON_EDIT: 'Distance_Rate_Tax_Reclaimable_On_Edit',
DISTANCE_RATE_TAX_RATE_EDIT: 'Distance_Rate_Tax_Rate_Edit',
UPGRADE: 'Workspace_Upgrade',
RULES: 'Policy_Rules',
},

EDIT_REQUEST: {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/Expensicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import ExpensifyLogoNew from '@assets/images/expensify-logo-new.svg';
import ExpensifyWordmark from '@assets/images/expensify-wordmark.svg';
import EyeDisabled from '@assets/images/eye-disabled.svg';
import Eye from '@assets/images/eye.svg';
import Feed from '@assets/images/feed.svg';
import Filter from '@assets/images/filter.svg';
import Filters from '@assets/images/filters.svg';
import Flag from '@assets/images/flag.svg';
Expand Down Expand Up @@ -386,4 +387,5 @@ export {
Filters,
CalendarSolid,
Filter,
Feed,
};
2 changes: 2 additions & 0 deletions src/components/Icon/Illustrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import ReceiptEnvelope from '@assets/images/simple-illustrations/simple-illustra
import ReceiptLocationMarker from '@assets/images/simple-illustrations/simple-illustration__receipt-location-marker.svg';
import ReceiptWrangler from '@assets/images/simple-illustrations/simple-illustration__receipt-wrangler.svg';
import ReceiptUpload from '@assets/images/simple-illustrations/simple-illustration__receiptupload.svg';
import Rules from '@assets/images/simple-illustrations/simple-illustration__rules.svg';
import SanFrancisco from '@assets/images/simple-illustrations/simple-illustration__sanfrancisco.svg';
import SendMoney from '@assets/images/simple-illustrations/simple-illustration__sendmoney.svg';
import ShieldYellow from '@assets/images/simple-illustrations/simple-illustration__shield.svg';
Expand Down Expand Up @@ -216,4 +217,5 @@ export {
Tire,
BigVault,
Filters,
Rules,
};
24 changes: 24 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,7 @@ export default {
travel: 'Travel',
members: 'Members',
accounting: 'Accounting',
rules: 'Rules',
displayedAs: 'Displayed as',
plan: 'Plan',
profile: 'Profile',
Expand Down Expand Up @@ -2831,6 +2832,10 @@ export default {
title: 'Spend',
subtitle: 'Enable optional functionality that helps you scale your team.',
},
manageSection: {
title: 'Manage',
subtitle: 'Add controls that help keep spend within budget.',
},
earnSection: {
title: 'Earn',
subtitle: 'Enable optional functionality to streamline your revenue and get paid faster.',
Expand Down Expand Up @@ -2898,6 +2903,10 @@ export default {
disconnectText: "To disable accounting, you'll need to disconnect your accounting connection from your workspace.",
manageSettings: 'Manage settings',
},
rules: {
title: 'Rules',
subtitle: 'Configure when receipts are required, flag high spend, and more.',
},
},
reportFields: {
addField: 'Add field',
Expand Down Expand Up @@ -3537,6 +3546,11 @@ export default {
description: `Add tax codes to your taxes for easy export of expenses to your accounting and payroll systems.`,
onlyAvailableOnPlan: 'Tax codes are only available on the Control plan, starting at ',
},
rules: {
title: 'Rules',
description: `Rules run in the background and keep your spend under control so you don't have to sweat the small stuff.\n\nRequire expense details like receipts and descriptions, set limits and defaults, and automate approvals and payments – all in one place.`,
onlyAvailableOnPlan: 'Rules are only available on the Control plan, starting at ',
},
pricing: {
amount: '$9 ',
perActiveMember: 'per active member per month.',
Expand Down Expand Up @@ -3568,6 +3582,16 @@ export default {
chatInAdmins: 'Chat in #admins',
addPaymentCard: 'Add payment card',
},
rules: {
individualExpenseRules: {
title: 'Expenses',
subtitle: 'Set spend controls and defaults for individual expenses. You can also create rules for',
},
expenseReportRules: {
title: 'Expense reports',
subtitle: 'Automate expense report compliance, approvals, and payment.',
},
},
},
getAssistancePage: {
title: 'Get assistance',
Expand Down
24 changes: 24 additions & 0 deletions src/languages/es.ts
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ export default {
travel: 'Viajes',
members: 'Miembros',
accounting: 'Contabilidad',
rules: 'Reglas',
plan: 'Plan',
profile: 'Perfil',
bankAccount: 'Cuenta bancaria',
Expand Down Expand Up @@ -2883,6 +2884,10 @@ export default {
title: 'Gasto',
subtitle: 'Habilita otras funcionalidades que ayudan a aumentar tu equipo.',
},
manageSection: {
title: 'Gestionar',
subtitle: 'Añade controles que ayudan a mantener los gastos dentro del presupuesto.',
},
earnSection: {
title: 'Gane',
subtitle: 'Habilita funciones opcionales para agilizar tus ingresos y recibir pagos más rápido.',
Expand Down Expand Up @@ -2950,6 +2955,10 @@ export default {
disconnectText: 'Para desactivar la contabilidad, desconecta tu conexión contable del espacio de trabajo.',
manageSettings: 'Gestionar la configuración',
},
rules: {
title: 'Reglas',
subtitle: 'Configura cuándo se requieren recibos, marca gastos altos y más.',
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
},
},
reportFields: {
addField: 'Añadir campo',
Expand Down Expand Up @@ -3590,6 +3599,11 @@ export default {
description: `Añada código de impuesto mayor a sus categorías para exportar fácilmente los gastos a sus sistemas de contabilidad y nómina.`,
onlyAvailableOnPlan: 'Los código de impuesto mayor solo están disponibles en el plan Control, a partir de ',
},
rules: {
title: 'Reglas',
description: `Las reglas se ejecutan en segundo plano y mantienen tus gastos bajo control para que no tengas que preocuparte por los detalles pequeños.\n\nExige detalles de gastos como recibos y descripciones, establece límites y valores predeterminados, y automatiza aprobaciones y pagos, todo en un solo lugar.`,
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
onlyAvailableOnPlan: 'Las reglas están disponibles solo en el plan Control, que comienza en ',
},
note: {
upgradeWorkspace: 'Mejore su espacio de trabajo para acceder a esta función, o',
learnMore: 'más información',
Expand Down Expand Up @@ -3621,6 +3635,16 @@ export default {
chatInAdmins: 'Chatea en #admins',
addPaymentCard: 'Agregar tarjeta de pago',
},
rules: {
individualExpenseRules: {
title: 'Gastos',
subtitle: 'Establece controles y valores predeterminados para gastos individuales. También puedes crear reglas para',
},
expenseReportRules: {
title: 'Informes de gastos',
subtitle: 'Automatiza el cumplimiento de los informes de gastos, las aprobaciones y el pago.',
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
getAssistancePage: {
title: 'Obtener ayuda',
Expand Down
6 changes: 6 additions & 0 deletions src/libs/API/parameters/SetPolicyRulesEnabledParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type SetPolicyRulesEnabledParams = {
policyID: string;
enabled: boolean;
};

export default SetPolicyRulesEnabledParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export type {default as ExportSearchItemsToCSVParams} from './ExportSearchItemsT
export type {default as UpdateExpensifyCardLimitParams} from './UpdateExpensifyCardLimitParams';
export type {CreateWorkspaceApprovalParams, UpdateWorkspaceApprovalParams, RemoveWorkspaceApprovalParams} from './WorkspaceApprovalParams';
export type {default as StartIssueNewCardFlowParams} from './StartIssueNewCardFlowParams';
export type {default as SetPolicyRulesEnabledParams} from './SetPolicyRulesEnabledParams';
export type {default as ConfigureExpensifyCardsForPolicyParams} from './ConfigureExpensifyCardsForPolicyParams';
export type {default as CreateExpensifyCardParams} from './CreateExpensifyCardParams';
export type {default as UpdateExpensifyCardTitleParams} from './UpdateExpensifyCardTitleParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const WRITE_COMMANDS = {
ENABLE_POLICY_REPORT_FIELDS: 'EnablePolicyReportFields',
ENABLE_POLICY_EXPENSIFY_CARDS: 'EnablePolicyExpensifyCards',
ENABLE_POLICY_INVOICING: 'EnablePolicyInvoicing',
SET_POLICY_RULES_ENABLED: 'SetPolicyRulesEnabled',
SET_POLICY_TAXES_CURRENCY_DEFAULT: 'SetPolicyCurrencyDefaultTax',
SET_POLICY_TAXES_FOREIGN_CURRENCY_DEFAULT: 'SetPolicyForeignCurrencyDefaultTax',
SET_POLICY_CUSTOM_TAX_NAME: 'SetPolicyCustomTaxName',
Expand Down Expand Up @@ -527,6 +528,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.ENABLE_POLICY_REPORT_FIELDS]: Parameters.EnablePolicyReportFieldsParams;
[WRITE_COMMANDS.ENABLE_POLICY_EXPENSIFY_CARDS]: Parameters.EnablePolicyExpensifyCardsParams;
[WRITE_COMMANDS.ENABLE_POLICY_INVOICING]: Parameters.EnablePolicyInvoicingParams;
[WRITE_COMMANDS.SET_POLICY_RULES_ENABLED]: Parameters.SetPolicyRulesEnabledParams;
[WRITE_COMMANDS.JOIN_POLICY_VIA_INVITE_LINK]: Parameters.JoinPolicyInviteLinkParams;
[WRITE_COMMANDS.ACCEPT_JOIN_REQUEST]: Parameters.AcceptJoinRequestParams;
[WRITE_COMMANDS.DECLINE_JOIN_REQUEST]: Parameters.DeclineJoinRequestParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const CENTRAL_PANE_WORKSPACE_SCREENS = {
[SCREENS.WORKSPACE.REPORT_FIELDS]: () => require<ReactComponentModule>('../../../../pages/workspace/reportFields/WorkspaceReportFieldsPage').default,
[SCREENS.WORKSPACE.EXPENSIFY_CARD]: () => require<ReactComponentModule>('../../../../pages/workspace/expensifyCard/WorkspaceExpensifyCardPage').default,
[SCREENS.WORKSPACE.DISTANCE_RATES]: () => require<ReactComponentModule>('../../../../pages/workspace/distanceRates/PolicyDistanceRatesPage').default,
[SCREENS.WORKSPACE.RULES]: () => require<ReactComponentModule>('../../../../pages/workspace/rules/PolicyRulesPage').default,
} satisfies Screens;

function FullScreenNavigator() {
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,9 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.WORKSPACE.DISTANCE_RATES]: {
path: ROUTES.WORKSPACE_DISTANCE_RATES.route,
},
[SCREENS.WORKSPACE.RULES]: {
path: ROUTES.WORKSPACE_RULES.route,
},
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,9 @@ type FullScreenNavigatorParamList = {
[SCREENS.WORKSPACE.EXPENSIFY_CARD]: {
policyID: string;
};
[SCREENS.WORKSPACE.RULES]: {
policyID: string;
};
};

type OnboardingModalNavigatorParamList = {
Expand Down
5 changes: 5 additions & 0 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function canUseNetSuiteUSATax(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.NETSUITE_USA_TAX) || canUseAllBetas(betas);
}

function canUseRules(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.RULES) || canUseAllBetas(betas);
}
marcaaron marked this conversation as resolved.
Show resolved Hide resolved

/**
* Link previews are temporarily disabled.
*/
Expand All @@ -52,4 +56,5 @@ export default {
canUseSpotnanaTravel,
canUseWorkspaceFeeds,
canUseNetSuiteUSATax,
canUseRules,
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
};
64 changes: 64 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type {
UpdateWorkspaceGeneralSettingsParams,
UpgradeToCorporateParams,
} from '@libs/API/parameters';
import type SetPolicyRulesEnabledParams from '@libs/API/parameters/SetPolicyRulesEnabledParams';
import type UpdatePolicyAddressParams from '@libs/API/parameters/UpdatePolicyAddressParams';
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import DateUtils from '@libs/DateUtils';
Expand Down Expand Up @@ -2937,6 +2938,68 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
}
}

const DISABLED_MAX_EXPENSE_VALUES: Pick<Policy, 'maxExpenseAmountNoReceipt' | 'maxExpenseAmount' | 'maxExpenseAge'> = {
maxExpenseAmountNoReceipt: CONST.DISABLED_MAX_EXPENSE_VALUE,
maxExpenseAmount: CONST.DISABLED_MAX_EXPENSE_VALUE,
maxExpenseAge: CONST.DISABLED_MAX_EXPENSE_VALUE,
};

function enablePolicyRules(policyID: string, enabled: boolean, disableRedirect = false) {
const policy = getPolicy(policyID);
const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
areRulesEnabled: enabled,
...(!enabled ? DISABLED_MAX_EXPENSE_VALUES : {}),
pendingFields: {
areRulesEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {
areRulesEnabled: null,
},
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
areRulesEnabled: !enabled,
...(!enabled
? {
maxExpenseAmountNoReceipt: policy?.maxExpenseAmountNoReceipt,
maxExpenseAmount: policy?.maxExpenseAmount,
maxExpenseAge: policy?.maxExpenseAge,
}
: {}),
pendingFields: {
areRulesEnabled: null,
},
},
},
],
};

const parameters: SetPolicyRulesEnabledParams = {policyID, enabled};
API.write(WRITE_COMMANDS.SET_POLICY_RULES_ENABLED, parameters, onyxData);

if (enabled && getIsNarrowLayout() && !disableRedirect) {
navigateWhenEnableFeature(policyID);
}
}

function enableDistanceRequestTax(policyID: string, customUnitName: string, customUnitID: string, attributes: Attributes) {
const policy = getPolicy(policyID);
const onyxData: OnyxData = {
Expand Down Expand Up @@ -3364,6 +3427,7 @@ export {
getAdminPoliciesConnectedToNetSuite,
getAdminPoliciesConnectedToSageIntacct,
hasInvoicingDetails,
enablePolicyRules,
};

export type {NewCustomUnit};
Loading
Loading