Skip to content

Commit f7e7eeb

Browse files
committed
Fixes #725 and #735
1 parent c033e0c commit f7e7eeb

2 files changed

Lines changed: 24 additions & 30 deletions

File tree

src/forms/FormsPage.tsx

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,25 @@ export const FormsPage = () => {
2727
placeholderData: [],
2828
});
2929

30-
const getRows = () => {
30+
const getRows = (isArchived: boolean) => {
3131
const result: JSX.Element[] = [];
32-
if (!forms.data?.length) {
32+
// Filter forms based on archived status since the API may return all forms
33+
const rawData = isArchived ? archivedForms.data : forms.data;
34+
const formData = rawData?.filter(form => isArchived ? form.archived === true : !form.archived);
35+
36+
if (!formData?.length) {
3337
result.push(
3438
<TableRow key="0">
35-
<TableCell>{Locale.label("forms.formsPage.noCustomMsg")}</TableCell>
39+
<TableCell>{isArchived ? Locale.label("forms.formsPage.noArch") : Locale.label("forms.formsPage.noCustomMsg")}</TableCell>
3640
</TableRow>
3741
);
3842
return result;
3943
}
40-
41-
const formData = selectedTab === "forms" ? forms.data : archivedForms.data;
4244
formData.forEach((form: FormInterface) => {
4345
const canEdit =
4446
UserHelper.checkAccess(Permissions.membershipApi.forms.admin) || (UserHelper.checkAccess(Permissions.membershipApi.forms.edit) && form.contentType !== "form") || form?.action === "admin";
4547
const editLink =
46-
canEdit && selectedTab === "forms" ? (
48+
canEdit && !isArchived ? (
4749
<SmallButton
4850
icon="edit"
4951
text="Edit"
@@ -57,7 +59,7 @@ export const FormsPage = () => {
5759
const formUrl = EnvironmentHelper.B1Url.replace("{key}", UserHelper.currentUserChurch.church.subDomain) + "/forms/" + form.id;
5860
const formLink = form.contentType === "form" ? <a href={formUrl}>{formUrl}</a> : null;
5961
const archiveLink =
60-
canEdit && selectedTab === "forms" ? (
62+
canEdit && !isArchived ? (
6163
<SmallButton
6264
icon="delete"
6365
text="Archive"
@@ -70,7 +72,7 @@ export const FormsPage = () => {
7072
/>
7173
) : null;
7274
const unarchiveLink =
73-
canEdit && selectedTab === "archived" ? (
75+
canEdit && isArchived ? (
7476
<SmallButton
7577
icon="undo"
7678
text="Restore"
@@ -109,22 +111,13 @@ export const FormsPage = () => {
109111
});
110112
};
111113

112-
const getArchivedRows = () => {
113-
const result: JSX.Element[] = [];
114-
if (!archivedForms.data?.length) {
115-
result.push(
116-
<TableRow key="0">
117-
<TableCell>{Locale.label("forms.formsPage.noArch")}</TableCell>
118-
</TableRow>
119-
);
120-
return result;
121-
}
122-
return getRows();
123-
};
114+
const getArchivedRows = () => getRows(true);
124115

125-
const getTableHeader = () => {
116+
const getTableHeader = (isArchived: boolean) => {
126117
const rows: JSX.Element[] = [];
127-
if (forms.data?.length === 0) {
118+
const rawData = isArchived ? archivedForms.data : forms.data;
119+
const formData = rawData?.filter(form => isArchived ? form.archived === true : !form.archived);
120+
if (!formData?.length) {
128121
return rows;
129122
}
130123
rows.push(
@@ -148,15 +141,16 @@ export const FormsPage = () => {
148141

149142
if (forms.isLoading || archivedForms.isLoading) return <Loading />;
150143

151-
const renderTable = (rows: JSX.Element[]) => (
144+
const renderTable = (rows: JSX.Element[], isArchived: boolean) => (
152145
<Table>
153-
<TableHead>{getTableHeader()}</TableHead>
146+
<TableHead>{getTableHeader(isArchived)}</TableHead>
154147
<TableBody>{rows}</TableBody>
155148
</Table>
156149
);
157150

158-
const formsCount = forms.data?.length || 0;
159-
const archivedCount = archivedForms.data?.length || 0;
151+
// Filter counts to match actual displayed forms
152+
const formsCount = forms.data?.filter(form => !form.archived)?.length || 0;
153+
const archivedCount = archivedForms.data?.filter(form => form.archived === true)?.length || 0;
160154

161155
const formsCard = (
162156
<Card sx={{ mt: getSidebar() ? 2 : 0 }}>
@@ -171,7 +165,7 @@ export const FormsPage = () => {
171165
</Typography>
172166
</Stack>
173167
</Box>
174-
<Box sx={{ p: 0 }}>{renderTable(getRows())}</Box>
168+
<Box sx={{ p: 0 }}>{renderTable(getRows(false), false)}</Box>
175169
</Card>
176170
);
177171

@@ -188,7 +182,7 @@ export const FormsPage = () => {
188182
</Typography>
189183
</Stack>
190184
</Box>
191-
<Box sx={{ p: 0 }}>{renderTable(getArchivedRows())}</Box>
185+
<Box sx={{ p: 0 }}>{renderTable(getArchivedRows(), true)}</Box>
192186
</Card>
193187
);
194188

@@ -203,7 +197,7 @@ export const FormsPage = () => {
203197
</>
204198
)
205199
},
206-
{ key: "archived", label: Locale.label("forms.formsPage.archForms"), content: archivedCard, hidden: archivedForms.data?.length === 0 },
200+
{ key: "archived", label: Locale.label("forms.formsPage.archForms"), content: archivedCard, hidden: archivedCount === 0 },
207201
];
208202

209203
return (

src/site/PagePreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const PagePreview: React.FC = () => {
6666
);
6767
}
6868

69-
const previewUrl = EnvironmentHelper.B1Url.replace('{subdomain}', context.userChurch?.church?.subDomain || '') + pageData.url;
69+
const previewUrl = EnvironmentHelper.B1Url.replace('{subdomain}', context.userChurch?.church?.subDomain || '') + pageData.url + '?t=' + Date.now();
7070

7171
return (
7272
<>

0 commit comments

Comments
 (0)