diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/AddEditLocalUnitsForm/i18n.json b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/AddEditLocalUnitsForm/i18n.json index a1720cadcb..d8ad9a8883 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/AddEditLocalUnitsForm/i18n.json +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/AddEditLocalUnitsForm/i18n.json @@ -10,8 +10,10 @@ "localUnitsFormFocalPerson": "Focal person", "localUnitsFormSource": "Source", "localUnitsAddressTitle": "Address and Contact", - "localUnitsSpecialtiesTitle": "Specialties and Capacity", + "localUnitsFacilityCategoryTitle": "Facility Category", + "localUnitsFacilityCapacityTitle": "Facility Capacity", "localUnitsHumanResourcesTitle": "Human Resources", + "localUnitsServicesTitle": "Services", "localUnitsFormAddress": "Address", "localUnitsFormLocality": "Locality", "localUnitsFormPostCode": "Post code", @@ -19,9 +21,12 @@ "localUnitsFormEmail": "Local unit email", "localUnitsFormWebsite": "Local unit website", "localUnitsFormType": "Local unit type", + "localUnitsVisibility": "Visibility", "localUnitsFormAffiliation": "Affiliation", "localUnitsFormOtherAffiliation": "Other Affiliation", "localUnitsFormFunctionality": "Functionality", + "localUnitsFormHealthFacilityType": "Health Facility type", + "localUnitsFormOtherFacilityType": "Other Facility type", "localUnitsFormHospitalType": "Hospital type", "localUnitsFormTeachingHospital": "Teaching Hospital", "localUnitsFormInPatientCapacity": "In-patient capacity", @@ -35,7 +40,7 @@ "localUnitsFormBloodServices": "Blood Services", "localUnitsFormProfessionalTrainingFacilities": "Professional training facilities", "localUnitsFormGeneralMedicalServices": "General medical services", - "localUnitsFormSpecialisation": "Specialisation", + "localUnitsFormSpecialist": "Specialist", "localUnitsFormSpecializedMedicalService": "Specialized medical beyond primary level", "localUnitsFormMaximumCapacity": "Maximum capacity", "localUnitsFormNumberOfIsolationRooms": "Number of isolation rooms", @@ -52,6 +57,7 @@ "localUnitsFormNursingAid": "Nursing aid", "localUnitsFormMidwife": "Midwife", "localUnitsFormOtherMedicalHeal": "Other medical heal", + "localUnitsFormOtherProfiles": "Other profiles", "localUnitsFormCommentsNS": "Comments by the NS", "localUnitsFormSubmitButtonLabel": "Submit" } diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/AddEditLocalUnitsForm/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/AddEditLocalUnitsForm/index.tsx index 57fd02ec30..34e6bf8a9e 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/AddEditLocalUnitsForm/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/AddEditLocalUnitsForm/index.tsx @@ -12,7 +12,10 @@ import { TextInput, } from '@ifrc-go/ui'; import { useTranslation } from '@ifrc-go/ui/hooks'; -import { stringNameSelector } from '@ifrc-go/ui/utils'; +import { + stringNameSelector, + stringValueSelector, +} from '@ifrc-go/ui/utils'; import { getErrorObject, getErrorString, @@ -20,6 +23,7 @@ import { useFormObject, } from '@togglecorp/toggle-form'; +import useGlobalEnums from '#hooks/domain/useGlobalEnums'; import useAlert from '#hooks/useAlert'; import { CountryOutletContext } from '#utils/outletContext'; import { @@ -35,6 +39,7 @@ import schema, { import i18n from './i18n.json'; import styles from './styles.module.css'; +import { isDefined, isNotDefined } from '@togglecorp/fujs'; type HealthLocalUnitFormFields = PartialLocalUnits['health']; type LocalUnitsOptionsType = GoApiResponse<'/api/v2/local-units-options/'>; @@ -45,20 +50,27 @@ type LocalUnitHealthFacility = NonNullable[number]; type LocalUnitProfessionalTraining = NonNullable[number]; type LocalUnitGeneralMedical = NonNullable[number]; +type LocalUnitPrimaryHealthCareCenter = NonNullable[number]; +type VisibilityOptions = NonNullable['api_visibility_choices']>[number] const localUnitTypeCodeSelector = (localUnit: LocalUnitType) => localUnit.code; const localUnitCoverageLevelSelector = (localUnit: LocalUnitCoverage) => localUnit.level; const localUnitAffiliationCodeSelector = (localUnit: LocalUnitAffiliation) => localUnit.code; const localUnitHealthFacilityCodeSelector = (localUnit: LocalUnitHealthFacility) => localUnit.code; +const LocalUnitPrimaryHealthCareCenterCodeSelector = ( + localUnit: LocalUnitPrimaryHealthCareCenter, +) => localUnit.code; const localUnitBloodServicesCodeSelector = (localUnit: LocalUnitBloodServices) => localUnit.code; const LocalUnitProfessionalTrainingCodeSelector = ( localUnit: LocalUnitProfessionalTraining, ) => localUnit.code; const localUnitGeneralMedicalCodeSelector = (localUnit: LocalUnitGeneralMedical) => localUnit.code; +const VisibilityOptions = (option: VisibilityOptions) => option.key; interface Props { viewMode?: boolean; localUnitsOptions?: LocalUnitsOptionsType; + onLocalUnitTypeClick: (type?: string) => void; } const defaultHealthValue = {}; @@ -67,9 +79,11 @@ function AddEditLocalUnitsForm(props: Props) { const { viewMode = false, localUnitsOptions, + onLocalUnitTypeClick, } = props; const alert = useAlert(); const strings = useTranslation(i18n); + const { api_visibility_choices: visibilityOptions } = useGlobalEnums(); const { countryId } = useOutletContext(); const { value, @@ -129,6 +143,21 @@ function AddEditLocalUnitsForm(props: Props) { [validate, setError, addLocalUnits, countryId], ); + const handleLocalUnitType = useCallback( + (type?: number) => { + setFieldValue(type, 'type'); + if (isNotDefined(localUnitsOptions)) { + return; + } + const selectedType = localUnitsOptions.type.find( + (opt) => opt.code === type, + ); + + onLocalUnitTypeClick(selectedType?.name); + }, + [setFieldValue, localUnitsOptions, onLocalUnitTypeClick], + ); + const error = getErrorObject(formError); const healthFormError = getErrorObject(error?.health); @@ -142,7 +171,7 @@ function AddEditLocalUnitsForm(props: Props) { name="type" options={localUnitsOptions?.type} value={value.type} - onChange={setFieldValue} + onChange={handleLocalUnitType} keySelector={localUnitTypeCodeSelector} labelSelector={stringNameSelector} readOnly={viewMode} @@ -161,6 +190,46 @@ function AddEditLocalUnitsForm(props: Props) { error={error?.subtype} /> + + + + + + + + + {value.type === TYPE_HEALTH_CARE ? ( <> - - - - - - - - - - - - ) : ( <> - - - - - - @@ -296,6 +293,7 @@ function AddEditLocalUnitsForm(props: Props) {
- - - +
+
- - - + + +
+
+
+
+
@@ -690,6 +701,91 @@ function AddEditLocalUnitsForm(props: Props) {
+ +
+ + + + + + + + + +
+
+ + + + + + +
+
+ + + @@ -802,6 +911,17 @@ function AddEditLocalUnitsForm(props: Props) { )} /> + + + { let formFields: LocalUnitsFormSchemaFields = { type: { required: true }, + visibility_display: { required: true }, location: {}, subtype: {}, - local_branch_name: {}, - english_branch_name: {}, + local_branch_name: { + required: true, + validations: [lengthSmallerThanCondition(200)], + }, + english_branch_name: { + validations: [lengthSmallerThanCondition(200)], + }, level: {}, - focal_person_en: {}, - focal_person_loc: {}, + focal_person_en: { + validations: [lengthSmallerThanCondition(200)], + }, + focal_person_loc: { + validations: [lengthSmallerThanCondition(200)], + required: true, + }, source_en: {}, address_en: {}, address_loc: {}, @@ -70,22 +82,28 @@ const schema: LocalUnitsFormSchema = { functionality: { required: true }, health_facility_type: { required: true }, other_facility_type: {}, - other_affiliation: { required: true }, - is_teaching_hospital: {}, - is_in_patient_capacity: {}, - is_isolation_rooms_wards: {}, - // address - focal_point_email: {}, - focal_point_position: {}, - focal_point_phone_number: {}, - // Specialities and capacity - // ?? - specialized_medical_beyond_primary_level: {}, - // ?? + other_affiliation: { + validations: [lengthSmallerThanCondition(500)], + }, + is_teaching_hospital: { required: true }, + is_in_patient_capacity: { required: true }, + is_isolation_rooms_wards: { required: true }, + focal_point_email: { + required: true, + validations: [lengthSmallerThanCondition(50)], + }, + focal_point_position: { + validations: [lengthSmallerThanCondition(50)], + }, + focal_point_phone_number: { + validations: [lengthSmallerThanCondition(50)], + }, + hospital_type: { required: true }, + specialized_medical_beyond_primary_level: { required: true }, other_services: {}, - blood_services: {}, + blood_services: { required: true }, professional_training_facilities: {}, - general_medical_services: {}, + general_medical_services: { required: true }, speciality: {}, maximum_capacity: {}, number_of_isolation_rooms: {}, @@ -94,8 +112,7 @@ const schema: LocalUnitsFormSchema = { ambulance_type_a: {}, ambulance_type_b: {}, ambulance_type_c: {}, - // Human resources - total_number_of_human_resource: {}, + total_number_of_human_resource: { required: true }, general_practitioner: {}, specialist: {}, residents_doctor: {}, diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/index.tsx index 6bbc8d8c7f..ede0a2ff19 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/AddEditLocalUnitsModal/index.tsx @@ -1,3 +1,4 @@ +import { useState } from 'react'; import { Modal } from '@ifrc-go/ui'; import { useTranslation } from '@ifrc-go/ui/hooks'; import { resolveToString } from '@ifrc-go/ui/utils'; @@ -22,6 +23,12 @@ function AddEditLocalUnitsModal(props: Props) { url: '/api/v2/local-units-options/', }); + const [localUnitType, setLocalUnitType] = useState('Administrative'); + + const handleLocalUnitType = (type?: string) => { + setLocalUnitType(type); + }; + return ( diff --git a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/index.tsx b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/index.tsx index caac158f5b..48a9499645 100644 --- a/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/index.tsx +++ b/app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/index.tsx @@ -1,5 +1,4 @@ import { useState } from 'react'; -import { useOutletContext } from 'react-router-dom'; import { Button, Container, @@ -15,7 +14,6 @@ import { import { _cs } from '@togglecorp/fujs'; import useAuth from '#hooks/domain/useAuth'; -import { type CountryOutletContext } from '#utils/outletContext'; import AddEditLocalUnitsModal from './AddEditLocalUnitsModal'; import LocalUnitsMap from './LocalUnitsMap';