Skip to content

Commit

Permalink
fix: remove supported_by when supported_by_organization is change…
Browse files Browse the repository at this point in the history
…d from `national_society`
  • Loading branch information
samshara committed Feb 22, 2024
1 parent 335a78d commit 031a15f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"namespace": "perWorkPlanForm",
"strings": {
"componentActionsInputPlaceholder": "Enter actions",
"componentSupportedByInputLabel": "Supported by",
"componentSupportedByInputPlaceholder": "Select NS",
"componentSupportedByInputLabel": "Supporting national society",
"componentSupportedByInputPlaceholder": "National society",
"componentDueDateInputLabel": "Due date",
"componentStatusInputLabel": "Status",
"componentSupportedByOrganizationInputLabel":"Supported by organization",
"componentSupportedByOrganizationInputLabel":"Supported by",
"componentOrganizationInputPlaceholder":"Organization type",
"componentStatusInputPlaceholder": "Select",
"componentStatusInputPlaceholder": "Status",
"componentHeading": "{componentNumber} ({componentLetter}). {componentTitle}",
"componentHeadingOther": "{componentNumber}. {componentTitle}"
}
Expand Down
17 changes: 13 additions & 4 deletions app/src/views/PerWorkPlanForm/PrioritizedActionInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCallback } from 'react';
import {
Container,
DateInput,
Expand All @@ -20,8 +21,8 @@ import {
import NationalSocietySelectInput from '#components/domain/NationalSocietySelectInput';
import NonFieldError from '#components/NonFieldError';
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
import { type GoApiResponse } from '#utils/restRequest';
import { NATIONAL_SOCIETY } from '#utils/constants';
import { type GoApiResponse } from '#utils/restRequest';

import { type PartialWorkPlan } from '../schema';

Expand All @@ -40,7 +41,7 @@ type PerWorkPlanOrganizationTypeOption = NonNullable<GlobalEnumsResponse['per_su
function statusKeySelector(option: PerWorkPlanStatusOption) {
return option.key;
}
function organizationTypeKeySelector(option:PerWorkPlanOrganizationTypeOption) {
function organizationTypeKeySelector(option: PerWorkPlanOrganizationTypeOption) {
return option.key;
}
interface Props {
Expand Down Expand Up @@ -75,6 +76,15 @@ function PrioritizedActionInput(props: Props) {
}),
);

const handleOrganizationTypeChange = useCallback((
organizationType: PerWorkPlanOrganizationTypeOption['key'] | undefined,
) => {
onFieldChange(organizationType, 'supported_by_organization_type' as const);
if (organizationType !== NATIONAL_SOCIETY) {
onFieldChange(undefined, 'supported_by');
}
}, [onFieldChange]);

return (
<Container
className={styles.prioritizedActionInput}
Expand Down Expand Up @@ -123,8 +133,7 @@ function PrioritizedActionInput(props: Props) {
label={strings.componentSupportedByOrganizationInputLabel}
placeholder={strings.componentOrganizationInputPlaceholder}
options={per_supported_by_organization_type}
withAsterisk
onChange={onFieldChange}
onChange={handleOrganizationTypeChange}
keySelector={organizationTypeKeySelector}
labelSelector={stringValueSelector}
value={value?.supported_by_organization_type}
Expand Down
4 changes: 1 addition & 3 deletions app/src/views/PerWorkPlanForm/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ export const workplanSchema: WorkPlanFormScheme = {
component: {},
actions: {},
due_date: {},
supported_by_organization_type: {
required: true,
},
supported_by_organization_type: {},
supported_by: {},
status: {
required: true,
Expand Down
7 changes: 5 additions & 2 deletions packages/ui/src/components/ExpandableContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useEffect, useRef, useCallback } from 'react';
import {
useCallback,
useEffect,
useRef,
} from 'react';
import {
ChevronDownLineIcon,
ChevronUpLineIcon,
} from '@ifrc-go/icons';

import { _cs } from '@togglecorp/fujs';

import Button from '#components/Button';
Expand Down

0 comments on commit 031a15f

Please sign in to comment.