Skip to content

Commit

Permalink
Merge pull request #43896 from rezkiy37/feature/43678-report-fields-o…
Browse files Browse the repository at this point in the history
…n-more-features-page

Integrate Report fields to the More features page
  • Loading branch information
mountiny authored Jun 20, 2024
2 parents dd5cd33 + 5bbbb11 commit ea9ea07
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ const CONST = {
SPOTNANA_TRAVEL: 'spotnanaTravel',
ACCOUNTING_ON_NEW_EXPENSIFY: 'accountingOnNewExpensify',
XERO_ON_NEW_EXPENSIFY: 'xeroOnNewExpensify',
REPORT_FIELDS_FEATURE: 'reportFieldsFeature',
},
BUTTON_STATES: {
DEFAULT: 'default',
Expand Down
4 changes: 3 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export default {
shared: 'Shared',
drafts: 'Drafts',
finished: 'Finished',
disable: 'Disable',
},
location: {
useCurrent: 'Use current location',
Expand Down Expand Up @@ -1022,7 +1023,6 @@ export default {
enabled: 'Two-factor authentication is now enabled!',
congrats: 'Congrats, now you’ve got that extra security.',
copy: 'Copy',
disable: 'Disable',
},
recoveryCodeForm: {
error: {
Expand Down Expand Up @@ -2260,6 +2260,8 @@ export default {
reportFields: {
delete: 'Delete field',
deleteConfirmation: 'Are you sure that you want to delete this field?',
disableReportFields: 'Disable report fields',
disableReportFieldsConfirmation: 'Are you sure? Text and date fields will be deleted, and lists will be disabled.',
},
tags: {
tagName: 'Tag name',
Expand Down
4 changes: 3 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export default {
shared: 'Compartidos',
drafts: 'Borradores',
finished: 'Finalizados',
disable: 'Deshabilitar',
},
connectionComplete: {
title: 'Conexión Completa',
Expand Down Expand Up @@ -1019,7 +1020,6 @@ export default {
enabled: '¡La autenticación de dos factores está ahora habilitada!',
congrats: 'Felicidades, ahora tienes esa seguridad adicional.',
copy: 'Copiar',
disable: 'Deshabilitar',
},
recoveryCodeForm: {
error: {
Expand Down Expand Up @@ -2296,6 +2296,8 @@ export default {
reportFields: {
delete: 'Eliminar campos',
deleteConfirmation: '¿Estás seguro de que quieres eliminar esta campos?',
disableReportFields: 'Desactivar campos de informe',
disableReportFieldsConfirmation: 'Estás seguro? Se eliminarán los campos de texto y fecha y se desactivarán las listas.',
},
tags: {
tagName: 'Nombre de etiqueta',
Expand Down
5 changes: 5 additions & 0 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function canUseXeroIntegration(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.XERO_ON_NEW_EXPENSIFY) || canUseAllBetas(betas);
}

function canUseReportFieldsFeature(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.REPORT_FIELDS_FEATURE) || canUseAllBetas(betas);
}

/**
* Link previews are temporarily disabled.
*/
Expand All @@ -67,4 +71,5 @@ export default {
canUseSpotnanaTravel,
canUseAccountingIntegrations,
canUseXeroIntegration,
canUseReportFieldsFeature,
};
4 changes: 4 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,10 @@ function enablePolicyReportFields(policyID: string, enabled: boolean) {
const parameters: EnablePolicyReportFieldsParams = {policyID, enabled};

API.write(WRITE_COMMANDS.ENABLE_POLICY_REPORT_FIELDS, parameters, onyxData);

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

function enablePolicyTaxes(policyID: string, enabled: boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function EnabledStep() {
onModalHide={() => setIsConfirmModalVisible(false)}
isVisible={isConfirmModalVisible}
prompt={translate('twoFactorAuth.disableTwoFactorAuthConfirmation')}
confirmText={translate('twoFactorAuth.disable')}
confirmText={translate('common.disable')}
cancelText={translate('common.cancel')}
shouldShowCancelButton
danger
Expand Down
42 changes: 39 additions & 3 deletions src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();
const {canUseAccountingIntegrations} = usePermissions();
const {canUseAccountingIntegrations, canUseReportFieldsFeature} = usePermissions();
const hasAccountingConnection = !!policy?.areConnectionsEnabled && !isEmptyObject(policy?.connections);
const isSyncTaxEnabled = !!policy?.connections?.quickbooksOnline?.config?.syncTax || !!policy?.connections?.xero?.config?.importTaxRates;
const policyID = policy?.id ?? '';

const [isOrganizeWarningModalOpen, setIsOrganizeWarningModalOpen] = useState<boolean>(false);
const [isIntegrateWarningModalOpen, setIsIntegrateWarningModalOpen] = useState<boolean>(false);
const [isOrganizeWarningModalOpen, setIsOrganizeWarningModalOpen] = useState(false);
const [isIntegrateWarningModalOpen, setIsIntegrateWarningModalOpen] = useState(false);
const [isReportFieldsWarningModalOpen, setIsReportFieldsWarningModalOpen] = useState(false);

const spendItems: Item[] = [
{
Expand Down Expand Up @@ -135,6 +136,28 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
},
];

if (canUseReportFieldsFeature) {
organizeItems.push({
icon: Illustrations.Pencil,
titleTranslationKey: 'workspace.moreFeatures.reportFields.title',
subtitleTranslationKey: 'workspace.moreFeatures.reportFields.subtitle',
isActive: policy?.areReportFieldsEnabled ?? false,
disabled: hasAccountingConnection,
pendingAction: policy?.pendingFields?.areReportFieldsEnabled,
action: (isEnabled: boolean) => {
if (hasAccountingConnection) {
setIsOrganizeWarningModalOpen(true);
return;
}
if (isEnabled) {
Policy.enablePolicyReportFields(policyID, true);
return;
}
setIsReportFieldsWarningModalOpen(true);
},
});
}

const integrateItems: Item[] = [
{
icon: Illustrations.Accounting,
Expand Down Expand Up @@ -275,6 +298,19 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
confirmText={translate('workspace.moreFeatures.connectionsWarningModal.manageSettings')}
cancelText={translate('common.cancel')}
/>
<ConfirmModal
title={translate('workspace.reportFields.disableReportFields')}
isVisible={isReportFieldsWarningModalOpen}
onConfirm={() => {
setIsReportFieldsWarningModalOpen(false);
Policy.enablePolicyReportFields(policyID, false);
}}
onCancel={() => setIsReportFieldsWarningModalOpen(false)}
prompt={translate('workspace.reportFields.disableReportFieldsConfirmation')}
confirmText={translate('common.disable')}
cancelText={translate('common.cancel')}
danger
/>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
Expand Down

0 comments on commit ea9ea07

Please sign in to comment.