diff --git a/src/api/agency/hasAgencyConsultants.ts b/src/api/agency/hasAgencyConsultants.ts index 85287efe..e212b5a4 100644 --- a/src/api/agency/hasAgencyConsultants.ts +++ b/src/api/agency/hasAgencyConsultants.ts @@ -13,7 +13,7 @@ export const hasAgencyConsultants = (agencyId: string) => { skipAuth: false, responseHandling: [FETCH_ERRORS.CATCH_ALL], }).then((data) => { - return data.total > 0; + return data.length > 0; }); }; diff --git a/src/components/Agency/AgencyAddAllgemeines.tsx b/src/components/Agency/AgencyAddAllgemeines.tsx index 1985aa59..8a12a0cc 100644 --- a/src/components/Agency/AgencyAddAllgemeines.tsx +++ b/src/components/Agency/AgencyAddAllgemeines.tsx @@ -281,7 +281,11 @@ export default function AgencieAddAllgemeines() { name="online" >
- + {t("yes")} diff --git a/src/components/Agency/AgencyEditAllgemeines.tsx b/src/components/Agency/AgencyEditAllgemeines.tsx index b7905a22..c8a4a238 100644 --- a/src/components/Agency/AgencyEditAllgemeines.tsx +++ b/src/components/Agency/AgencyEditAllgemeines.tsx @@ -23,6 +23,7 @@ import { UserRole } from "../../enums/UserRole"; import { SliderFormField } from "../SliderFormField"; import { useFeatureContext } from "../../context/FeatureContext"; import { useUserRoles } from "../../hooks/useUserRoles.hook"; +import { hasAgencyConsultants } from "../../api/agency/hasAgencyConsultants"; const { Paragraph } = Typography; const { Item } = Form; @@ -63,6 +64,8 @@ export default function AgencieEditAllgemeines() { const [readOnlyAgencyGender, setReadOnlyAgencyGender] = useState(true); const [readOnlyAgencyAge, setReadOnlyAgencyAge] = useState(true); + const [agencyHasConsultants, setAgencyHasConsultants] = + useState(true); const currentPath = useLocation().pathname; const [, agencyID] = currentPath.match(/.*\/([^/]+)\/[^/]+/); const [, hasRole] = useUserRoles(); @@ -212,10 +215,12 @@ export default function AgencieEditAllgemeines() { Promise.all([ getAgencyPostCodeRange(agencyId), getAgencyDataAgencyId(agencyId), + hasAgencyConsultants(agencyId), ]).then((values) => { const agencyPostCodeRangesResponse = values[0]; /* eslint no-underscore-dangle: ["error", { "allow": ["_embedded"] }] */ const agencyData = values[1]._embedded; + setAgencyHasConsultants(values[2]); setAgencyPostCodeRanges(agencyPostCodeRangesResponse); setPostCodeRangesSwitchState(agencyPostCodeRangesResponse); setAgencyModel(agencyData); @@ -469,7 +474,10 @@ export default function AgencieEditAllgemeines() { {t("yes")} diff --git a/src/components/Agency/AgencyEditErstberatung.tsx b/src/components/Agency/AgencyEditErstberatung.tsx index 1a7b6b74..1c75008c 100644 --- a/src/components/Agency/AgencyEditErstberatung.tsx +++ b/src/components/Agency/AgencyEditErstberatung.tsx @@ -17,20 +17,20 @@ import ErstberatungEditModal from "./ErstberatungEditModal"; import getAgencyEventTypes from "../../api/agency/getAgencyEventTypes"; import getConsultantForAgencyEventTypes from "../../api/agency/getConsultantForAgencyEventTypes"; import EventTypeDeletionModal from "./EventTypeDeletionModal"; +import { agencyConsultants } from "../../api/agency/hasAgencyConsultants"; const { Paragraph } = Typography; export default function AgencieEditErstberatung() { const { t } = useTranslation(); const [topics, setTopics] = useState([]); - const [apiAgencyEventTypes, setApiAgencyEventTypes] = useState< - AgencyEventTypes[] - >([]); const [showEditModal, setShowEditModal] = useState(false); const [showDeleteModal, setShowDeleteModal] = useState(false); const [showNewModal, setShowNewModal] = useState(false); const [editableData, setEditableData] = useState(undefined); const [eventTypeDelete, setEventTypeDelete] = useState(undefined); + const [allAgencyConsultants, setAllAgencyConsultants] = + useState(undefined); const [isLoading, setIsLoading] = useState(true); const [tableState] = useState({ current: 1, @@ -57,11 +57,14 @@ export default function AgencieEditErstberatung() { }; const getAgencyData = () => { - getAgencyEventTypes(agencyId).then((resp: AgencyEventTypes[]) => { - setApiAgencyEventTypes(resp); - const agencyEventTypes = transformData(resp); + Promise.all([ + getAgencyEventTypes(agencyId), + agencyConsultants(agencyId), + ]).then((resp) => { + const agencyEventTypes = transformData(resp[0]); setTopics(agencyEventTypes); setIsLoading(false); + setAllAgencyConsultants(resp[1]); }); }; @@ -235,14 +238,14 @@ export default function AgencieEditErstberatung() { showEditModal={showNewModal} handleCancel={handleCancelNew} handleSave={handleSaveNew} - apiData={apiAgencyEventTypes} + allAgencyConsultants={allAgencyConsultants} /> void; handleSave?: (callback: Function) => void; editableData: AgencyEditData; - apiData: AgencyEventTypes[]; + allAgencyConsultants: ConsultantInterface[]; }) { const { t } = useTranslation(); const [formInstance] = Form.useForm(); const currentPath = useLocation().pathname; const [, agencyId] = currentPath.match(/.*\/([^/]+)\/[^/]+/); - const [advisors, setAdvisors] = useState([]); useEffect(() => { - const newConsultants = []; - props?.apiData[0]?.consultants?.map((consultant: ConsultantInterface) => { - return newConsultants.push({ - id: consultant.consultantId, - name: consultant.consultantName, - }); + formInstance.setFieldsValue({ + name: props?.editableData?.name, + description: props.editableData?.description, + url: props.editableData?.url, + duration: props.editableData?.duration, + advisor: props.editableData?.advisor?.map((advisor) => { + return { + label: advisor.name, + value: advisor.id, + }; + }), + location: props.editableData?.location, }); - setAdvisors(newConsultants); - }, [props.apiData]); + }, [props.editableData]); return ( { - props.handleCancel(() => {}); - }} + onCancel={() => props.handleCancel(() => {})} destroyOnClose cancelText={t( "agency.edit.erstberatung.modal_edit_consultation_type.cancel" @@ -104,19 +102,6 @@ export default function ErstberatungEditModal(props: { labelAlign="left" labelWrap layout="vertical" - initialValues={{ - name: props?.editableData?.name, - description: props?.editableData?.description, - url: props?.editableData?.url, - duration: props?.editableData?.duration, - advisor: props?.editableData?.advisor?.map((advisor) => { - return { - label: advisor.name, - value: advisor.id, - }; - }), - location: props?.editableData?.location, - }} > { + options={props.allAgencyConsultants?.map((consultant) => { return { - label: advisor.name, - value: advisor.id, + label: consultant.consultantName, + value: consultant.consultantId, }; })} /> diff --git a/src/components/Agency/ErstberatungNewModal.tsx b/src/components/Agency/ErstberatungNewModal.tsx index eb9b0b8a..af98737f 100644 --- a/src/components/Agency/ErstberatungNewModal.tsx +++ b/src/components/Agency/ErstberatungNewModal.tsx @@ -3,10 +3,9 @@ import { useTranslation } from "react-i18next"; import Title from "antd/es/typography/Title"; import TextArea from "antd/lib/input/TextArea"; import { useLocation } from "react-router"; -import { useEffect, useState } from "react"; import { SelectFormField } from "../SelectFormField"; import postConsultantForAgencyEventTypes from "../../api/agency/postConsultantForAgencyEventTypes"; -import { AgencyEventTypes, ConsultantInterface } from "../../types/agencyEdit"; +import { ConsultantInterface } from "../../types/agencyEdit"; const { Paragraph } = Typography; const { Item } = Form; @@ -15,24 +14,12 @@ export default function ErstberatungNewModal(props: { showEditModal: boolean; handleCancel?: (callback: Function) => void; handleSave?: (callback: Function) => void; - apiData: AgencyEventTypes[]; + allAgencyConsultants: ConsultantInterface[]; }) { const { t } = useTranslation(); const [formInstance] = Form.useForm(); const currentPath = useLocation().pathname; const [, agencyId] = currentPath.match(/.*\/([^/]+)\/[^/]+/); - const [advisors, setAdvisors] = useState([]); - - useEffect(() => { - const newConsultants = []; - props?.apiData[0]?.consultants?.map((consultant: ConsultantInterface) => { - return newConsultants.push({ - id: consultant.consultantId, - name: consultant.consultantName, - }); - }); - setAdvisors(newConsultants); - }, [props?.apiData]); return ( { + formInstance.resetFields(); props.handleCancel(() => {}); }} destroyOnClose @@ -151,10 +139,10 @@ export default function ErstberatungNewModal(props: { isMulti allowClear placeholder="agency.edit.erstberatung.modal_new_consultation_type.advisor" - options={advisors?.map((advisor) => { + options={props.allAgencyConsultants?.map((consultant) => { return { - label: advisor.name, - value: advisor.id, + label: consultant.consultantName, + value: consultant.consultantId, }; })} /> diff --git a/src/types/agencyEdit.d.ts b/src/types/agencyEdit.d.ts index d7329146..3e82d0d5 100644 --- a/src/types/agencyEdit.d.ts +++ b/src/types/agencyEdit.d.ts @@ -14,7 +14,7 @@ interface AdvisorInterface { id: string; } -interface ConsultantInterface { +export interface ConsultantInterface { consultantId: string; consultantName: string; }