Skip to content

Commit

Permalink
Disable document type dropdown (#2391)
Browse files Browse the repository at this point in the history
* refactor(backoffice-v2): document type is no longer editable

* now disabling document type just for businesses
  • Loading branch information
Omri-Levy committed May 19, 2024
1 parent c4136a5 commit 143cbcb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { TWorkflowById } from '@/domains/workflows/fetchers';

export const checkIsBusiness = (workflow: TWorkflowById) =>
workflow?.context?.entity?.type === 'business';
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { useDocumentPageImages } from '@/lib/blocks/hooks/useDocumentPageImages'
import { motionBadgeProps } from '@/lib/blocks/motion-badge-props';
import { useCaseState } from '@/pages/Entity/components/Case/hooks/useCaseState/useCaseState';
import {
checkIsEditable,
composePickableCategoryType,
extractCountryCodeFromWorkflow,
getIsEditable,
isExistingSchemaForDocument,
} from '@/pages/Entity/hooks/useEntityLogic/utils';
import { selectWorkflowDocuments } from '@/pages/Entity/selectors/selectWorkflowDocuments';
Expand All @@ -28,6 +28,7 @@ import { X } from 'lucide-react';
import * as React from 'react';
import { FunctionComponent, useCallback, useMemo } from 'react';
import { toTitleCase } from 'string-ts';
import { checkIsBusiness } from '@/common/utils/check-is-business/check-is-business';

export const useDocumentBlocks = ({
workflow,
Expand Down Expand Up @@ -376,6 +377,7 @@ export const useDocumentBlocks = ({
]) => {
const fieldValue = value || (properties?.[title] ?? '');
const isEditableDecision = isDoneWithRevision || !decision?.status;
const isEditableType = title === 'type' && !checkIsBusiness(workflow);

return {
title,
Expand All @@ -386,7 +388,8 @@ export const useDocumentBlocks = ({
isEditable:
isEditableDecision &&
caseState.writeEnabled &&
getIsEditable(isEditable, title),
isEditableType &&
checkIsEditable({ isEditable, field: title }),
dropdownOptions,
minimum: formatMinimum,
maximum: formatMaximum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ const uniqueArrayByKey = (array: AnyArray, key: PropertyKey) => {
return [...new Map(array.map(item => [item[key], item])).values()] as TDropdownOption[];
};

const NONE_EDITABLE_FIELDS = ['category'] as const;
export const getIsEditable = (isEditable: boolean, title: string) => {
if (NONE_EDITABLE_FIELDS.includes(title)) return false;
const NON_EDITABLE_FIELDS = ['category'] as const;

return isEditable;
export const checkIsEditable = ({ isEditable, field }: { isEditable: boolean; field: string }) => {
return !NON_EDITABLE_FIELDS.includes(field) && isEditable;
};

export const composePickableCategoryType = (
Expand All @@ -37,17 +36,20 @@ export const composePickableCategoryType = (
documentsSchemas: TDocument[],
config?: Record<any, any> | null,
) => {
const documentCategoryDropdownOptions: Array<TDropdownOption> = [];
const documentTypesDropdownOptions: Array<TDropdownOption> = [];
const documentCategoryDropdownOptions: TDropdownOption[] = [];
const documentTypesDropdownOptions: TDropdownOption[] = [];
documentsSchemas.forEach(document => {
const category = document.category;

if (category) {
documentCategoryDropdownOptions.push({
value: category,
label: toTitleCase(category),
});
}

const type = document.type;

if (type) {
documentTypesDropdownOptions.push({
dependantOn: 'category',
Expand All @@ -67,7 +69,7 @@ export const composePickableCategoryType = (
...composeDataFormCell('type', typeDropdownOptions, typeValue, isEditable),
};
};
export const isExistingSchemaForDocument = (documentsSchemas: Array<TDocument>) => {
export const isExistingSchemaForDocument = (documentsSchemas: TDocument[]) => {
return documentsSchemas?.length > 0;
};

Expand Down

0 comments on commit 143cbcb

Please sign in to comment.