From 88e251967f42ab28e9ad9fb8791767ccd6397594 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 5 Aug 2024 11:28:44 +0200 Subject: [PATCH 01/43] Test navigation --- src/languages/en.ts | 5 +- src/languages/es.ts | 3 + src/libs/Permissions.ts | 2 +- ...orkspaceWorkflowsApprovalsApproverPage.tsx | 2 +- .../WorkspaceWorkflowsApprovalsCreatePage.tsx | 66 ++++++++++++++++++- 5 files changed, 74 insertions(+), 4 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 8cc1f0887e75..649aa1ef87a4 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1285,7 +1285,9 @@ export default { monthlyOffsetErrorMessage: "Monthly frequency couldn't be changed. Please try again or contact support.", }, workflowsCreateApprovalsPage: { - title: 'Add approval workflow', + title: 'Confirm', + header: 'Add more approvers and confirm.', + addApproverRow: 'Additional approver', }, workflowsEditApprovalsPage: { title: 'Edit approval workflow', @@ -2045,6 +2047,7 @@ export default { edit: 'Edit workspace', enabled: 'Enabled', disabled: 'Disabled', + everyone: 'Everyone', delete: 'Delete workspace', settings: 'Settings', reimburse: 'Reimbursements', diff --git a/src/languages/es.ts b/src/languages/es.ts index b659123c0632..38870e756b47 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1295,6 +1295,8 @@ export default { }, workflowsCreateApprovalsPage: { title: 'Añadir flujo de aprobación', + header: 'Agrega más aprobadores y confirma.', + addApproverRow: 'Añadir aprobador', }, workflowsEditApprovalsPage: { title: 'Edicion flujo de aprobación', @@ -2080,6 +2082,7 @@ export default { edit: 'Editar espacio de trabajo', enabled: 'Activada', disabled: 'Desactivada', + everyone: 'Todos', delete: 'Eliminar espacio de trabajo', settings: 'Configuración', reimburse: 'Reembolsos', diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index a7348e143e60..e433d81fc24d 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -4,7 +4,7 @@ import type {IOUType} from '@src/CONST'; import type Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return !!betas?.includes(CONST.BETAS.ALL); + return !!betas?.includes(CONST.BETAS.ALL) || true; } function canUseDefaultRooms(betas: OnyxEntry): boolean { diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx index 8d4f2178bb6b..a4bb26d8ff33 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx @@ -162,7 +162,7 @@ function WorkspaceWorkflowsApprovalsApproverPageBeta({policy, personalDetails, i ); const firstApprover = approvalWorkflow?.approvers?.[0]?.email ?? ''; - if (!approvalWorkflow?.isBeingEdited && firstApprover) { + if (approvalWorkflow?.isBeingEdited && firstApprover) { Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EDIT.getRoute(route.params.policyID, firstApprover)); } else { Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(route.params.policyID)); diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx index d7a4696446cc..144f169d01ab 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx @@ -1,9 +1,14 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React from 'react'; +import React, {useCallback} from 'react'; +import {View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import ScreenWrapper from '@components/ScreenWrapper'; +import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {FullScreenNavigatorParamList} from '@libs/Navigation/types'; import * as PolicyUtils from '@libs/PolicyUtils'; @@ -11,13 +16,17 @@ import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading'; import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; +import type {ApprovalWorkflow} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; type WorkspaceWorkflowsApprovalsCreatePageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps; function WorkspaceWorkflowsApprovalsCreatePage({policy, isLoadingReportData = true, route}: WorkspaceWorkflowsApprovalsCreatePageProps) { const {translate} = useLocalize(); + const [approvalWorkflow] = useOnyx(ONYXKEYS.APPROVAL_WORKFLOW); // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundView = (isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy); @@ -41,12 +50,67 @@ function WorkspaceWorkflowsApprovalsCreatePage({policy, isLoadingReportData = tr title={translate('workflowsCreateApprovalsPage.title')} onBackButtonPress={Navigation.goBack} /> + {approvalWorkflow && ( + + )} ); } +function X({approvalWorkflow, policyID}: {approvalWorkflow: ApprovalWorkflow; policyID: string}) { + const styles = useThemeStyles(); + const {translate, toLocaleOrdinal} = useLocalize(); + + const approverDescription = useCallback( + (index: number) => + // @ts-expect-error Fix later + approvalWorkflow.approvers.length > 1 ? `${toLocaleOrdinal(index + 1, true)} ${translate('workflowsPage.approver').toLowerCase()}` : `${translate('workflowsPage.approver')}`, + [approvalWorkflow.approvers.length, toLocaleOrdinal, translate], + ); + + return ( + + {translate('workflowsCreateApprovalsPage.header')} + + m.displayName).join(', ')} + titleStyle={styles.textNormalThemeText} + description={translate('workflowsExpensesFromPage.title')} + descriptionTextStyle={styles.textLabelSupportingNormal} + onPress={() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(policyID))} + shouldShowRightIcon + wrapperStyle={[styles.sectionMenuItemTopDescription]} + /> + + {approvalWorkflow.approvers.map((approver, approverIndex) => ( + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverIndex))} + shouldShowRightIcon + wrapperStyle={[styles.sectionMenuItemTopDescription]} + /> + ))} + + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approvalWorkflow.approvers.length))} + shouldShowRightIcon + wrapperStyle={[styles.sectionMenuItemTopDescription]} + /> + + ); +} + WorkspaceWorkflowsApprovalsCreatePage.displayName = 'WorkspaceWorkflowsApprovalsCreatePage'; export default withPolicyAndFullscreenLoading(WorkspaceWorkflowsApprovalsCreatePage); From b0878c5396c627e08c3ccceaae6fbfd100312085 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 5 Aug 2024 14:46:26 +0200 Subject: [PATCH 02/43] Fix navigating between screens for create flow --- src/ROUTES.ts | 8 ++++---- src/libs/Navigation/types.ts | 3 +++ src/libs/WorkflowUtils.ts | 3 +-- ...orkspaceWorkflowsApprovalsApproverPage.tsx | 15 ++++++++------- .../WorkspaceWorkflowsApprovalsCreatePage.tsx | 18 ++++++++++++------ ...paceWorkflowsApprovalsExpensesFromPage.tsx | 19 ++++++++++++------- src/types/onyx/ApprovalWorkflow.ts | 4 ++-- tests/unit/WorkflowUtilsTest.ts | 5 ----- 8 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index f08227b71519..5fc49d20bf65 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -621,7 +621,7 @@ const ROUTES = { }, WORKSPACE_WORKFLOWS_APPROVALS_NEW: { route: 'settings/workspaces/:policyID/workflows/approvals/new', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/workflows/approvals/new` as const, + getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/workflows/approvals/new` as const, backTo), }, WORKSPACE_WORKFLOWS_APPROVALS_EDIT: { route: 'settings/workspaces/:policyID/workflows/approvals/:firstApproverEmail/edit', @@ -629,12 +629,12 @@ const ROUTES = { }, WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM: { route: 'settings/workspaces/:policyID/workflows/approvals/expenses-from', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/workflows/approvals/expenses-from` as const, + getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/workflows/approvals/expenses-from` as const, backTo), }, WORKSPACE_WORKFLOWS_APPROVALS_APPROVER: { route: 'settings/workspaces/:policyID/workflows/approvals/approver', - getRoute: (policyID: string, approverIndex?: number) => - `settings/workspaces/${policyID}/workflows/approvals/approver${approverIndex !== undefined ? `?approverIndex=${approverIndex}` : ''}` as const, + getRoute: (policyID: string, approverIndex?: number, backTo?: string) => + getUrlWithBackToParam(`settings/workspaces/${policyID}/workflows/approvals/approver${approverIndex !== undefined ? `?approverIndex=${approverIndex}` : ''}` as const, backTo), }, WORKSPACE_WORKFLOWS_PAYER: { route: 'settings/workspaces/:policyID/workflows/payer', diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index f4d65a16fd71..d6243afdcb9b 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1110,6 +1110,7 @@ type FullScreenNavigatorParamList = { }; [SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_NEW]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_EDIT]: { policyID: string; @@ -1117,10 +1118,12 @@ type FullScreenNavigatorParamList = { }; [SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_EXPENSES_FROM]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_APPROVER]: { policyID: string; approverIndex?: number; + backTo?: Routes; }; [SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_FREQUENCY]: { policyID: string; diff --git a/src/libs/WorkflowUtils.ts b/src/libs/WorkflowUtils.ts index 1365de4f881b..3cb0a5700801 100644 --- a/src/libs/WorkflowUtils.ts +++ b/src/libs/WorkflowUtils.ts @@ -8,7 +8,7 @@ const EMPTY_APPROVAL_WORKFLOW: ApprovalWorkflow = { members: [], approvers: [], isDefault: false, - isBeingEdited: false, + flow: 'create', isLoading: false, }; @@ -105,7 +105,6 @@ function convertPolicyEmployeesToApprovalWorkflows({employees, defaultApprover, members: [], approvers, isDefault: defaultApprover === submitsTo, - isBeingEdited: false, }; } approvalWorkflows[submitsTo].members.push(member); diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx index a4bb26d8ff33..bbaf2019c35d 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx @@ -161,13 +161,14 @@ function WorkspaceWorkflowsApprovalsApproverPageBeta({policy, personalDetails, i approverIndex, ); - const firstApprover = approvalWorkflow?.approvers?.[0]?.email ?? ''; - if (approvalWorkflow?.isBeingEdited && firstApprover) { - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EDIT.getRoute(route.params.policyID, firstApprover)); + if (approvalWorkflow?.flow === 'create') { + Navigation.goBack(); + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(route.params.policyID), CONST.NAVIGATION.TYPE.UP); } else { - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(route.params.policyID)); + const firstApprover = approvalWorkflow?.approvers?.[0]?.email ?? ''; + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EDIT.getRoute(route.params.policyID, firstApprover)); } - }, [approvalWorkflow?.approvers, approvalWorkflow?.isBeingEdited, approverIndex, personalDetails, policy?.employeeList, route.params.policyID, selectedApproverEmail]); + }, [approvalWorkflow, approverIndex, personalDetails, policy?.employeeList, route.params.policyID, selectedApproverEmail]); const nextButton = useMemo( () => ( @@ -183,11 +184,11 @@ function WorkspaceWorkflowsApprovalsApproverPageBeta({policy, personalDetails, i ); const goBack = useCallback(() => { - if (!approvalWorkflow?.isBeingEdited) { + if (approvalWorkflow?.flow === 'create' && !route.params.backTo) { Workflow.clearApprovalWorkflowApprovers(); } Navigation.goBack(); - }, [approvalWorkflow?.isBeingEdited]); + }, [approvalWorkflow?.flow, route.params.backTo]); const toggleApprover = (approver: SelectionListApprover) => { if (selectedApproverEmail === approver.login) { diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx index 144f169d01ab..13f18eee6a88 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx @@ -82,7 +82,7 @@ function X({approvalWorkflow, policyID}: {approvalWorkflow: ApprovalWorkflow; po titleStyle={styles.textNormalThemeText} description={translate('workflowsExpensesFromPage.title')} descriptionTextStyle={styles.textLabelSupportingNormal} - onPress={() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(policyID))} + onPress={() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(policyID, ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID)))} shouldShowRightIcon wrapperStyle={[styles.sectionMenuItemTopDescription]} /> @@ -90,22 +90,28 @@ function X({approvalWorkflow, policyID}: {approvalWorkflow: ApprovalWorkflow; po {approvalWorkflow.approvers.map((approver, approverIndex) => ( Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverIndex))} + onPress={() => + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverIndex, ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID))) + } shouldShowRightIcon - wrapperStyle={[styles.sectionMenuItemTopDescription]} + wrapperStyle={styles.sectionMenuItemTopDescription} /> ))} Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approvalWorkflow.approvers.length))} + onPress={() => + Navigation.navigate( + ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approvalWorkflow.approvers.length, ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID)), + ) + } shouldShowRightIcon - wrapperStyle={[styles.sectionMenuItemTopDescription]} + wrapperStyle={styles.sectionMenuItemTopDescription} /> ); diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx index 4a504275bbb2..330fcae9841f 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage.tsx @@ -129,20 +129,25 @@ function WorkspaceWorkflowsApprovalsExpensesFromPage({policy, isLoadingReportDat const members: Member[] = selectedMembers.map((member) => ({displayName: member.text, avatar: member.icons?.[0]?.source, email: member.login})); Workflow.setApprovalWorkflowMembers(members); - const firstApprover = approvalWorkflow?.approvers?.[0]?.email; - if (approvalWorkflow?.isBeingEdited && firstApprover) { - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EDIT.getRoute(route.params.policyID, firstApprover)); - } else { + if (route.params.backTo) { + Navigation.navigate(route.params.backTo); + return; + } + + if (approvalWorkflow?.flow === 'create') { Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(route.params.policyID, 0)); + } else { + const firstApprover = approvalWorkflow?.approvers?.[0]?.email ?? ''; + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EDIT.getRoute(route.params.policyID, firstApprover)); } - }, [approvalWorkflow?.approvers, approvalWorkflow?.isBeingEdited, route.params.policyID, selectedMembers]); + }, [approvalWorkflow?.approvers, approvalWorkflow?.flow, route.params.backTo, route.params.policyID, selectedMembers]); const goBack = useCallback(() => { - if (!approvalWorkflow?.isBeingEdited) { + if (approvalWorkflow?.flow === 'create' && !route.params.backTo) { Workflow.clearApprovalWorkflow(); } Navigation.goBack(); - }, [approvalWorkflow?.isBeingEdited]); + }, [approvalWorkflow?.flow, route.params.backTo]); const nextButton = useMemo( () => ( diff --git a/src/types/onyx/ApprovalWorkflow.ts b/src/types/onyx/ApprovalWorkflow.ts index b5bce8037fdc..2cd839ced97d 100644 --- a/src/types/onyx/ApprovalWorkflow.ts +++ b/src/types/onyx/ApprovalWorkflow.ts @@ -80,9 +80,9 @@ type ApprovalWorkflow = { isDefault: boolean; /** - * Is this workflow being edited vs created + * What is the current flow of the workflow, used to navigate between different screens */ - isBeingEdited: boolean; + flow?: 'create' | 'edit'; /** * Whether we are waiting for the API action to complete diff --git a/tests/unit/WorkflowUtilsTest.ts b/tests/unit/WorkflowUtilsTest.ts index 6359ba01ed23..cbea0dd525a7 100644 --- a/tests/unit/WorkflowUtilsTest.ts +++ b/tests/unit/WorkflowUtilsTest.ts @@ -43,7 +43,6 @@ function buildWorkflow(memberIDs: number[], approverIDs: number[], workflow: Par members: memberIDs.map(buildMember), approvers: approverIDs.map((id) => buildApprover(id)), isDefault: false, - isBeingEdited: false, ...workflow, }; } @@ -385,7 +384,6 @@ describe('WorkflowUtils', () => { members: [buildMember(1), buildMember(2)], approvers: [buildApprover(1)], isDefault: true, - isBeingEdited: false, }; const employeeList: PolicyEmployeeList = { '1@example.com': buildPolicyEmployee(1, {forwardsTo: 'previous@example.com', submitsTo: 'previous@example.com', role: 'admin'}), @@ -405,7 +403,6 @@ describe('WorkflowUtils', () => { members: [buildMember(4), buildMember(5), buildMember(6)], approvers: [buildApprover(1, {forwardsTo: '2@example.com'}), buildApprover(2, {forwardsTo: '2@example.com'}), buildApprover(3)], isDefault: false, - isBeingEdited: false, }; const employeeList: PolicyEmployeeList = { '1@example.com': buildPolicyEmployee(1, {forwardsTo: 'previous@example.com', submitsTo: 'previous@example.com', role: 'admin'}), @@ -438,7 +435,6 @@ describe('WorkflowUtils', () => { buildApprover(1, {forwardsTo: '2@example.com'}), ], isDefault: false, - isBeingEdited: false, }; const employeeList: PolicyEmployeeList = { '1@example.com': buildPolicyEmployee(1, {forwardsTo: 'previous@example.com', submitsTo: 'previous@example.com', role: 'admin'}), @@ -462,7 +458,6 @@ describe('WorkflowUtils', () => { members: [buildMember(4), buildMember(5), buildMember(6)], approvers: [buildApprover(1, {forwardsTo: '2@example.com'}), buildApprover(2, {forwardsTo: '2@example.com'}), buildApprover(3)], isDefault: false, - isBeingEdited: false, }; const employeeList: PolicyEmployeeList = { '1@example.com': buildPolicyEmployee(1, {forwardsTo: 'previous@example.com', submitsTo: 'previous@example.com', role: 'admin'}), From 66c99d3c09e4d3ebbecb0852605c55888abb03c9 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 5 Aug 2024 15:33:00 +0200 Subject: [PATCH 03/43] Attach API action --- .../API/parameters/WorkspaceApprovalParams.ts | 4 +- src/libs/actions/Workflow.ts | 12 +-- .../WorkspaceWorkflowsApprovalsCreatePage.tsx | 97 ++++++++++++------- 3 files changed, 69 insertions(+), 44 deletions(-) diff --git a/src/libs/API/parameters/WorkspaceApprovalParams.ts b/src/libs/API/parameters/WorkspaceApprovalParams.ts index 67f96b7852e7..1f3d7bddbdc9 100644 --- a/src/libs/API/parameters/WorkspaceApprovalParams.ts +++ b/src/libs/API/parameters/WorkspaceApprovalParams.ts @@ -1,9 +1,7 @@ -import type {PolicyEmployee} from '@src/types/onyx'; - type CreateWorkspaceApprovalParams = { authToken: string; policyID: string; - employees: PolicyEmployee[]; + employees: string; }; type UpdateWorkspaceApprovalParams = CreateWorkspaceApprovalParams; diff --git a/src/libs/actions/Workflow.ts b/src/libs/actions/Workflow.ts index 77607080bc7a..0d52d89d400d 100644 --- a/src/libs/actions/Workflow.ts +++ b/src/libs/actions/Workflow.ts @@ -33,7 +33,7 @@ Onyx.connect({ }); function createApprovalWorkflow(policyID: string, approvalWorkflow: ApprovalWorkflow) { - const policy = allPolicies?.[policyID]; + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; if (!authToken || !policy) { return; @@ -85,12 +85,12 @@ function createApprovalWorkflow(policyID: string, approvalWorkflow: ApprovalWork }, ]; - const parameters: CreateWorkspaceApprovalParams = {policyID, authToken, employees: Object.values(updatedEmployees)}; + const parameters: CreateWorkspaceApprovalParams = {policyID, authToken, employees: JSON.stringify(Object.values(updatedEmployees))}; API.write(WRITE_COMMANDS.CREATE_WORKSPACE_APPROVAL, parameters, {optimisticData, failureData, successData}); } function updateApprovalWorkflow(policyID: string, approvalWorkflow: ApprovalWorkflow) { - const policy = allPolicies?.[policyID]; + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; if (!authToken || !policy) { return; @@ -135,12 +135,12 @@ function updateApprovalWorkflow(policyID: string, approvalWorkflow: ApprovalWork }, ]; - const parameters: UpdateWorkspaceApprovalParams = {policyID, authToken, employees: Object.values(updatedEmployees)}; + const parameters: UpdateWorkspaceApprovalParams = {policyID, authToken, employees: JSON.stringify(Object.values(updatedEmployees))}; API.write(WRITE_COMMANDS.UPDATE_WORKSPACE_APPROVAL, parameters, {optimisticData, failureData, successData}); } function removeApprovalWorkflow(policyID: string, approvalWorkflow: ApprovalWorkflow) { - const policy = allPolicies?.[policyID]; + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; if (!authToken || !policy) { return; @@ -195,7 +195,7 @@ function removeApprovalWorkflow(policyID: string, approvalWorkflow: ApprovalWork }, ]; - const parameters: RemoveWorkspaceApprovalParams = {policyID, authToken, employees: Object.values(updatedEmployees)}; + const parameters: RemoveWorkspaceApprovalParams = {policyID, authToken, employees: JSON.stringify(Object.values(updatedEmployees))}; API.write(WRITE_COMMANDS.REMOVE_WORKSPACE_APPROVAL, parameters, {optimisticData, failureData, successData}); } diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx index 13f18eee6a88..0f6605067bdf 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx @@ -1,11 +1,14 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useCallback} from 'react'; +import React, {useCallback, useEffect} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; +import Button from '@components/Button'; +import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import ScreenWrapper from '@components/ScreenWrapper'; +import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -15,6 +18,7 @@ import * as PolicyUtils from '@libs/PolicyUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading'; import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading'; +import * as Workflow from '@userActions/Workflow'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -25,12 +29,22 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject'; type WorkspaceWorkflowsApprovalsCreatePageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps; function WorkspaceWorkflowsApprovalsCreatePage({policy, isLoadingReportData = true, route}: WorkspaceWorkflowsApprovalsCreatePageProps) { + const styles = useThemeStyles(); const {translate} = useLocalize(); - const [approvalWorkflow] = useOnyx(ONYXKEYS.APPROVAL_WORKFLOW); + const [approvalWorkflow, approvalWorkflowMetadata] = useOnyx(ONYXKEYS.APPROVAL_WORKFLOW); // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundView = (isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy); + const createApprovalWorkflow = useCallback(() => { + if (!approvalWorkflow) { + return; + } + + Workflow.createApprovalWorkflow(route.params.policyID, approvalWorkflow); + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS.getRoute(route.params.policyID)); + }, [approvalWorkflow, route.params.policyID]); + return ( + {approvalWorkflowMetadata.status === 'loading' && } {approvalWorkflow && ( - )} + +