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 15 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.
13 changes: 13 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ 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],
EMPTY_MAX_EXPENSE_AMOUNT_NO_RECEIPT: 10000000000,
EMPTY_MAX_EXPENSE_AMOUNT: 10000000000,
EMPTY_MAX_EXPENSE_AGE: 10000000000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this DISABLED_MAX_EXPENSE_VALUE and just use it for all three of these cases?


// 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 @@ -2081,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 @@ -2413,6 +2417,7 @@ const CONST = {
WORKSPACE_BANK_ACCOUNT: 'WorkspaceBankAccount',
WORKSPACE_SETTINGS: 'WorkspaceSettings',
WORKSPACE_FEATURES: 'WorkspaceFeatures',
WORKSPACE_RULES: 'WorkspaceRules',
},
get EXPENSIFY_EMAILS() {
return [
Expand Down Expand Up @@ -5459,6 +5464,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 @@ -923,6 +923,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 @@ -438,6 +438,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 @@ -86,6 +86,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 @@ -214,4 +215,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 @@ -2100,6 +2100,7 @@ export default {
travel: 'Travel',
members: 'Members',
accounting: 'Accounting',
rules: 'Rules',
displayedAs: 'Displayed as',
plan: 'Plan',
profile: 'Profile',
Expand Down Expand Up @@ -2809,6 +2810,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 @@ -2876,6 +2881,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 @@ -3515,6 +3524,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 @@ -3546,6 +3560,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 categories and tags.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want "categories" and "tags" to be links?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these should be links :) I've already fixed that

Screen.Recording.2024-08-19.at.15.59.16.mov
Screen.Recording.2024-08-19.at.15.58.44.mov

},
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 @@ -2134,6 +2134,7 @@ export default {
travel: 'Viajes',
members: 'Miembros',
accounting: 'Contabilidad',
rules: 'Reglas',
plan: 'Plan',
profile: 'Perfil',
bankAccount: 'Cuenta bancaria',
Expand Down Expand Up @@ -2861,6 +2862,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 @@ -2928,6 +2933,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 @@ -3568,6 +3577,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 @@ -3599,6 +3613,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 categorías y etiquetas.',
},
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 @@ -271,5 +271,6 @@ 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';
3 changes: 3 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,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 @@ -525,6 +526,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 All @@ -548,6 +550,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.REQUEST_EXPENSIFY_CARD_LIMIT_INCREASE]: Parameters.RequestExpensifyCardLimitIncreaseParams;
[WRITE_COMMANDS.CLEAR_OUTSTANDING_BALANCE]: null;
[WRITE_COMMANDS.CANCEL_BILLING_SUBSCRIPTION]: Parameters.CancelBillingSubscriptionParams;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
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 @@ -1093,6 +1093,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 @@ -1193,6 +1193,9 @@ type FullScreenNavigatorParamList = {
[SCREENS.WORKSPACE.EXPENSIFY_CARD]: {
policyID: string;
};
[SCREENS.WORKSPACE.RULES]: {
policyID: string;
};
};

type OnboardingModalNavigatorParamList = {
Expand Down
64 changes: 64 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 @@ -2925,6 +2926,68 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) {
}
}

const EMPTY_MAX_EXPENSE_VALUES: Pick<Policy, 'maxExpenseAmountNoReceipt' | 'maxExpenseAmount' | 'maxExpenseAge'> = {
maxExpenseAmountNoReceipt: CONST.EMPTY_MAX_EXPENSE_AMOUNT_NO_RECEIPT,
maxExpenseAmount: CONST.EMPTY_MAX_EXPENSE_AMOUNT,
maxExpenseAge: CONST.EMPTY_MAX_EXPENSE_AGE,
};

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 ? EMPTY_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 @@ -3351,6 +3414,7 @@ export {
getAdminPoliciesConnectedToNetSuite,
getAdminPoliciesConnectedToSageIntacct,
hasInvoicingDetails,
enablePolicyRules,
};

export type {NewCustomUnit};
Loading
Loading