Skip to content

Commit 5d79e45

Browse files
authored
Version 0.42.2 (#988)
- fix: fallback in mail for value of conditional block
2 parents f3585f0 + 7c3afc2 commit 5d79e45

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "conveniat27",
3-
"version": "0.42.1",
3+
"version": "0.42.2",
44
"description": "The official website of conveniat27",
55
"license": "MIT",
66
"author": "Cyrill Püntener v/o JPG (cyrill.puentener@cevi.ch)",
@@ -33,10 +33,10 @@
3333
},
3434
"lint-staged": {
3535
"**/package.json": "sort-package-json",
36-
"*.{md,mdx,yml,json}": "prettier --write",
36+
"*.{md,mdx,yml,json}": "prettier --config-path .prettierrc.json --write --cache --experimental-cli .",
3737
"*.{js,jsx,ts,tsx}": [
38-
"prettier --write",
39-
"eslint --cache --fix"
38+
"prettier --config-path .prettierrc.json --write --cache --experimental-cli .",
39+
"eslint -c eslint.config.mjs --fix --quiet --cache ."
4040
]
4141
},
4242
"dependencies": {

src/features/payload-cms/components/form/hooks/use-form-steps.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ export interface UseFormStepsReturn {
1919
prev: (event?: React.MouseEvent) => void;
2020
}
2121

22+
const scrollToTop = (formId?: string): void => {
23+
if (typeof globalThis !== 'undefined') {
24+
const element = formId ? document.querySelector(formId) : undefined;
25+
if (element) {
26+
// scroll to element - 60px to account for sticky nav
27+
const topPos = element.getBoundingClientRect().top + window.pageYOffset - 100;
28+
window.scrollTo({ top: topPos, behavior: 'smooth' });
29+
}
30+
}
31+
};
32+
2233
export const useFormSteps = (
2334
sections: FormSection[],
2435
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -96,6 +107,7 @@ export const useFormSteps = (
96107

97108
if (isValid && !isLastStep) {
98109
setCurrentStepIndex((previous) => previous + 1);
110+
scrollToTop(formId);
99111
}
100112
return isValid;
101113
};
@@ -105,6 +117,7 @@ export const useFormSteps = (
105117
if (!isFirstStep) {
106118
setCurrentStepIndex((previous_) => previous_ - 1);
107119
}
120+
scrollToTop(formId);
108121
};
109122

110123
return {

src/features/payload-cms/payload-cms/plugins/form/hooks/link-job-submission.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const noJobSelectedMessage: StaticTranslationString = {
3232
const getJobSelectionBlockNames = (fields: unknown[] | null | undefined = []): string[] => {
3333
if (!fields || !Array.isArray(fields)) return [];
3434
return fields.reduce<string[]>((accumulator, field) => {
35-
if (!field || typeof field !== 'object') return accumulator;
35+
if (field === null || field === undefined || typeof field !== 'object') return accumulator;
3636
const f = field as { blockType?: string; name?: string; fields?: unknown[] | null };
3737

3838
if (f.blockType === 'jobSelection' && typeof f.name === 'string') {
@@ -99,6 +99,17 @@ export const linkJobSubmission: CollectionBeforeChangeHook<FormSubmission> = asy
9999
}
100100

101101
const submissionData = (data.submissionData as SubmissionField[] | undefined) ?? [];
102+
103+
// If a job selection is within an optional block and not selected, its field
104+
// is completely missing from submissionData. Append missing fields as empty.
105+
for (const blockName of blockNames) {
106+
if (!submissionData.some((entry) => entry.field === blockName)) {
107+
submissionData.push({ field: blockName, value: '' });
108+
}
109+
}
110+
111+
data.submissionData = submissionData as NonNullable<FormSubmission['submissionData']>;
112+
102113
const entriesToProcess = submissionData.filter((entry) => blockNames.includes(entry.field));
103114

104115
if (entriesToProcess.length === 0) {

0 commit comments

Comments
 (0)