Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/Dashboard/Agents/AgentListController.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiAgentGetList, ApiOptionLists, SortOrder } from "need4deed-sdk";
import { AgentCardList } from "./AgentCardList";
import { useEffect } from "react";
import { DashboardListLoading } from "@/components/Dashboard/common/DashboardListLoading";
import { useGetQuery, usePageParam } from "@/hooks";
import { apiPathAgent, cacheTTL } from "@/config/constants";
import { serializeAgentFilters } from "./helpers";
Expand Down Expand Up @@ -29,7 +30,7 @@ export const AgentListController = ({ setNumOfAgents, sortOrder, isFiltersOpen,
}),
);

const { data, count } = useGetQuery<ApiAgentGetList[]>({
const { data, count, isLoading } = useGetQuery<ApiAgentGetList[]>({
queryKey: ["agents"],
apiPath: `${apiPathAgent}/`,
params: {
Expand All @@ -48,6 +49,8 @@ export const AgentListController = ({ setNumOfAgents, sortOrder, isFiltersOpen,
setNumOfAgents(count);
}, [count, setNumOfAgents]);

if (isLoading) return <DashboardListLoading />;

return (
<AgentCardList
agents={agents}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from "react";
import { DashboardListLoading } from "@/components/Dashboard/common/DashboardListLoading";
import { apiPathOpportunity, cacheTTL } from "@/config/constants";
import { useGetQuery, usePageParam } from "@/hooks";
import { ApiVolunteerOpportunityGetList, ApiOptionLists, SortOrder } from "need4deed-sdk";
Expand Down Expand Up @@ -64,7 +65,7 @@ export function OpportunityListController({

const backendSortOrder = isAppointmentSort(sortOrder) ? SortOrder.NewToOld : (sortOrder as SortOrder);

const { data, count } = useGetQuery<ApiVolunteerOpportunityGetList[]>({
const { data, count, isLoading } = useGetQuery<ApiVolunteerOpportunityGetList[]>({
queryKey: ["opportunities"],
apiPath: `${apiPathOpportunity}/`,
params: {
Expand All @@ -85,6 +86,8 @@ export function OpportunityListController({
setNumOfOpps(count);
}, [count, setNumOfOpps]);

if (isLoading) return <DashboardListLoading />;

return (
<OpportunityCardList
activitiesList={apiFilterOptions?.activity}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useApiLanguages } from "@/components/Dashboard/Profile/sections/Volunte
import { useUpdateOpportunityAccompanyingDetails } from "@/hooks/useUpdateOpportunityAccompanyingDetails";
import { zodResolver } from "@hookform/resolvers/zod";
import { de, enUS } from "date-fns/locale";
import { ApiOpportunityGet, TranslatedIntoType } from "need4deed-sdk";
import { ApiOpportunityAccompanyingDetails, ApiOpportunityGet, Lang, Option, TranslatedIntoType } from "need4deed-sdk";
import { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -121,6 +121,17 @@ export const AccompanyingDetails = forwardRef<EditableSectionRef, Props>(functio
.map((lang) => keyToLabel[String(lang.id)] || String(lang.id))
.join(", ");

// appointmentDistrict is server-calculated from postcode — read from API response, never from form state
const rawDetails = opportunity.accompanyingDetails as ApiOpportunityAccompanyingDetails & {
appointmentPostcode?: string;
appointmentDistrict?: Option;
};
const lang = i18n.language as Lang;
const districtTitle =
rawDetails?.appointmentDistrict?.title?.[lang] ?? rawDetails?.appointmentDistrict?.title?.de ?? "";
const postcode = rawDetails?.appointmentPostcode || "";
const postcodeDisplay = postcode && districtTitle ? `${postcode}, ${districtTitle}` : postcode;

return (
<FormProvider {...methods}>
<Container data-testid="accompanying-details-container" $isEditing={isEditing}>
Expand All @@ -139,7 +150,11 @@ export const AccompanyingDetails = forwardRef<EditableSectionRef, Props>(functio
minAppointmentDate={minAppointmentDate}
/>
) : (
<AccompanyingDetailsDisplay values={formValues} languageLabel={languageLabel} />
<AccompanyingDetailsDisplay
values={formValues}
languageLabel={languageLabel}
postcodeDisplay={postcodeDisplay}
/>
)}
</Container>
</FormProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { DateFieldRow, Details } from "./styles";
type Props = {
values: AccompanyingDetailsFormData;
languageLabel: string;
postcodeDisplay: string;
};

export const AccompanyingDetailsDisplay = ({ values, languageLabel }: Props) => {
export const AccompanyingDetailsDisplay = ({ values, languageLabel, postcodeDisplay }: Props) => {
const { t } = useTranslation();

return (
Expand All @@ -28,7 +29,7 @@ export const AccompanyingDetailsDisplay = ({ values, languageLabel }: Props) =>
mode="display"
type="text"
label={t("dashboard.opportunityProfile.accompanyingDetails.appointmentPostcode")}
value={values.appointmentPostcode || ""}
value={postcodeDisplay}
setValue={() => {}}
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useEffect } from "react";

import { DashboardListLoading } from "@/components/Dashboard/common/DashboardListLoading";
import { apiPathVolunteer, cacheTTL, TABLE_LIMIT } from "@/config/constants";
import { useGetQuery, usePageParam } from "@/hooks";
import { ApiOptionLists, ApiVolunteerGetList, SortOrder } from "need4deed-sdk";
import { CardsFilter } from "./Filters/types";
import { serializeFilters } from "./helpers";
import { VolunteerCardList } from "./VolunteerCardList"; // We will modify this component
import { VolunteerCardList } from "./VolunteerCardList";
import { VolunteerTableList } from "./VolunteerTableList";

const CARD_COLUMNS = 3;
Expand Down Expand Up @@ -49,7 +50,7 @@ export function VolunteerListController({
sortOrder,
filter: serializedFilter,
};
const { data, count } = useGetQuery<ApiVolunteerGetList[]>({
const { data, count, isLoading } = useGetQuery<ApiVolunteerGetList[]>({
queryKey: ["volunteers"],
apiPath: apiPathVolunteer,
params,
Expand All @@ -61,6 +62,8 @@ export function VolunteerListController({
setNumOfVols(count);
}, [count, setNumOfVols]);

if (isLoading) return <DashboardListLoading />;

if (isListView) {
return (
<VolunteerTableList
Expand Down
20 changes: 20 additions & 0 deletions src/components/Dashboard/common/DashboardListLoading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Heading4 } from "@/components/styled/text";
import { useTranslation } from "react-i18next";
import styled from "styled-components";

const Container = styled.div`
display: flex;
flex: 1;
min-height: var(--dashboard-home-container-min-height, 300px);
align-items: center;
justify-content: center;
`;

export function DashboardListLoading() {
const { t } = useTranslation();
return (
<Container>
<Heading4>{t("dashboard.home.content.loading")}</Heading4>
</Container>
);
}
1 change: 0 additions & 1 deletion src/hooks/useUpdateOpportunityAccompanyingDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export type OpportunityAccompanyingDetailsUpdateData = {
accompanyingDetails: {
appointmentAddress?: string;
appointmentPostcode?: string;
appointmentDistrict?: string;
appointmentDate?: string;
appointmentTime?: string;
refugeeNumber?: string;
Expand Down
Loading