Skip to content

Commit 53e0ac2

Browse files
committed
Added planTypeId, contentType and contentId to plans.
1 parent 4a288ea commit 53e0ac2

5 files changed

Lines changed: 33 additions & 36 deletions

File tree

src/helpers/Interfaces.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ export interface PlanTypeInterface {
7272
ministryId?: string;
7373
name?: string;
7474
}
75+
76+
export interface PlanInterface {
77+
id?: string;
78+
churchId?: string;
79+
name?: string;
80+
ministryId?: string;
81+
planTypeId?: string;
82+
serviceDate?: Date;
83+
notes?: string;
84+
serviceOrder?: boolean;
85+
contentType?: string;
86+
contentId?: string;
87+
}

src/plans/PlanPage.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import React from "react";
22
import { useParams } from "react-router-dom";
33
import { ApiHelper, Locale, PageHeader } from "@churchapps/apphelper";
4+
import { type PlanInterface } from "../helpers";
45
import { Assignment } from "./components/Assignment";
56
import { Box, Stack, Button, Container, Typography } from "@mui/material";
67
import { Assignment as AssignmentIcon, Album as AlbumIcon } from "@mui/icons-material";
78
import { ServiceOrder } from "./components/ServiceOrder";
89

9-
export interface PlanInterface {
10-
id?: string;
11-
churchId?: string;
12-
name?: string;
13-
ministryId?: string;
14-
serviceDate?: Date;
15-
notes?: string;
16-
serviceOrder?: boolean;
17-
}
10+
1811

1912
export const PlanPage = () => {
2013
const params = useParams();

src/plans/components/PlanEdit.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import { FormControl, InputLabel, MenuItem, Select, TextField, type SelectChangeEvent } from "@mui/material";
33
import { DateHelper, ErrorMessages, InputBox, Locale } from "@churchapps/apphelper";
4+
import { type PlanInterface } from "../../helpers";
45
import { useMutation } from "@tanstack/react-query";
56
import { queryClient } from "../../queryClient";
67

@@ -10,15 +11,7 @@ interface Props {
1011
updatedFunction: () => void;
1112
}
1213

13-
export interface PlanInterface {
14-
id?: string;
15-
churchId?: string;
16-
name?: string;
17-
ministryId?: string;
18-
serviceDate?: Date;
19-
notes?: string;
20-
serviceOrder?: boolean;
21-
}
14+
2215

2316
export const PlanEdit = (props: Props) => {
2417
const [plan, setPlan] = React.useState<PlanInterface>(props.plan);

src/plans/components/PlanList.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import { Add as AddIcon, Assignment as AssignmentIcon, CalendarMonth as CalendarIcon, Edit as EditIcon, EventNote as EventNoteIcon } from "@mui/icons-material";
66
import { Link } from "react-router-dom";
77
import { type GroupInterface } from "@churchapps/helpers";
8+
import { type PlanInterface } from "../../helpers";
89
import { ArrayHelper, DateHelper, Locale, Loading, UserHelper, Permissions } from "@churchapps/apphelper";
910
import { PlanEdit } from "./PlanEdit";
1011
import { MinistryList } from "./MinistryList";
@@ -16,32 +17,24 @@ interface Props {
1617
planTypeId?: string;
1718
}
1819

19-
export interface PlanInterface {
20-
id?: string;
21-
churchId?: string;
22-
name?: string;
23-
ministryId?: string;
24-
planTypeId?: string;
25-
serviceDate?: Date;
26-
notes?: string;
27-
serviceOrder?: boolean;
28-
}
20+
2921

3022
export const PlanList = memo((props: Props) => {
3123
const [plan, setPlan] = React.useState<PlanInterface>(null);
3224
const canEdit = UserHelper.checkAccess(Permissions.membershipApi.plans.edit);
3325

3426
const plansQuery = useQuery<PlanInterface[]>({
35-
queryKey: ["/plans", "DoingApi"],
27+
queryKey: props.planTypeId ? [`/plans/types/${props.planTypeId}`, "DoingApi"] : ["/plans", "DoingApi"],
3628
placeholderData: [],
3729
});
3830

3931
const plans = React.useMemo(() => {
40-
let filtered = ArrayHelper.getAll(plansQuery.data || [], "ministryId", props.ministry.id);
32+
// When planTypeId is provided, the API already returns filtered data
4133
if (props.planTypeId) {
42-
filtered = ArrayHelper.getAll(filtered, "planTypeId", props.planTypeId);
34+
return plansQuery.data || [];
4335
}
44-
return filtered;
36+
// When no planTypeId, filter by ministry only
37+
return ArrayHelper.getAll(plansQuery.data || [], "ministryId", props.ministry.id);
4538
}, [plansQuery.data, props.ministry.id, props.planTypeId]);
4639

4740
const addPlan = useCallback(() => {
@@ -50,18 +43,23 @@ export const PlanList = memo((props: Props) => {
5043
const name = DateHelper.prettyDate(date);
5144
setPlan({
5245
ministryId: props.ministry.id,
46+
planTypeId: props.planTypeId,
5347
serviceDate: date,
5448
name,
5549
notes: "",
5650
serviceOrder: true,
5751
});
58-
}, [props.ministry.id]);
52+
}, [props.ministry.id, props.planTypeId]);
5953

6054
const handleUpdated = useCallback(() => {
6155
setPlan(null);
6256
plansQuery.refetch();
57+
// Invalidate both the specific plan type query and the general plans query
58+
if (props.planTypeId) {
59+
queryClient.invalidateQueries({ queryKey: [`/plans/types/${props.planTypeId}`, "DoingApi"] });
60+
}
6361
queryClient.invalidateQueries({ queryKey: ["/plans", "DoingApi"] });
64-
}, [plansQuery]);
62+
}, [plansQuery, props.planTypeId]);
6563

6664
if (plan && canEdit) {
6765
return <PlanEdit plan={plan} plans={plans} updatedFunction={handleUpdated} />;
@@ -240,7 +238,7 @@ export const PlanList = memo((props: Props) => {
240238
))}
241239
</Stack>
242240

243-
<MinistryList />
241+
{!props.planTypeId && <MinistryList />}
244242
</Box>
245243
);
246244
});

src/plans/components/PlanTypeList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const PlanTypeList = React.memo(({ ministry }: Props) => {
1818
const canEdit = UserHelper.checkAccess(Permissions.membershipApi.plans.edit);
1919

2020
const planTypes = useQuery<PlanTypeInterface[]>({
21-
queryKey: [`/planTypes?ministryId=${ministry.id}`, "DoingApi"],
21+
queryKey: [`/planTypes/ministryId/${ministry.id}`, "DoingApi"],
2222
enabled: !!ministry.id,
2323
placeholderData: [],
2424
});

0 commit comments

Comments
 (0)