Skip to content

Commit 18e07f3

Browse files
authored
Merge pull request #357 from openscript-ch/355-carer-in-entry-form-is-not-required
355 carer in entry form is not required
2 parents 883d342 + d947f83 commit 18e07f3

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

.changeset/small-wombats-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@quassel/frontend": patch
3+
---
4+
5+
Fix validation if no carer is selected in Entry form

apps/frontend/src/components/EntitySelect.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Combobox, Group, IconPlus, ScrollArea, TextInput, TextInputProps, useCombobox } from "@quassel/ui";
1+
import { ActionIcon, Combobox, Group, IconPlus, IconX, ScrollArea, TextInput, TextInputProps, useCombobox } from "@quassel/ui";
22
import { useEffect, useState } from "react";
33
import { i18n } from "../stores/i18n";
44
import { useStore } from "@nanostores/react";
@@ -88,7 +88,28 @@ export function EntitySelect<T extends { id: number }>({ value, onChange, data,
8888
value={searchValue}
8989
onChange={({ target: { value } }) => {
9090
setSearchValue(value);
91+
92+
if (value === "") {
93+
combobox.resetSelectedOption();
94+
onChange?.(-1);
95+
}
9196
}}
97+
readOnly={value !== -1}
98+
rightSection={
99+
<ActionIcon
100+
variant="subtle"
101+
color="gray"
102+
size="sm"
103+
onClick={() => {
104+
combobox.resetSelectedOption();
105+
onChange?.(-1);
106+
107+
setSearchValue("");
108+
}}
109+
>
110+
<IconX />
111+
</ActionIcon>
112+
}
92113
onClick={() => combobox.openDropdown()}
93114
onFocus={() => combobox.openDropdown()}
94115
onBlur={() => combobox.closeDropdown()}

apps/frontend/src/components/questionnaire/calendar/EntryForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ export function EntityForm({ onSave, onDelete, onAddCarer, onAddLanguage, action
5353
initialValues: {
5454
startedAt: "",
5555
endedAt: "",
56-
carer: 0,
56+
carer: -1,
5757
weekday: 0,
5858
entryLanguages: [{ ratio: 100 }],
5959
},
6060
validate: {
6161
startedAt: isNotEmpty(t.validationNotEmpty),
6262
endedAt: isNotEmpty(t.validationNotEmpty),
63-
carer: isNotEmpty(t.validationNotEmpty),
63+
carer: (value) => (value === -1 || !value ? t.validationNotEmpty : undefined),
6464
entryLanguages: {
6565
ratio: (value) => {
6666
const fieldError = isInRange({ min: 1, max: 100 }, t.validationRatio)(value);
@@ -69,7 +69,7 @@ export function EntityForm({ onSave, onDelete, onAddCarer, onAddLanguage, action
6969
const listError = getTotalRatio() !== 100;
7070
if (listError) return t.validationTotalRatio;
7171
},
72-
language: isNotEmpty(t.validationNotEmpty),
72+
language: (value) => (value === -1 || !value ? t.validationNotEmpty : undefined),
7373
},
7474
},
7575
});

libs/ui/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export {
121121
IconFilter,
122122
IconPlus,
123123
IconReportAnalytics,
124+
IconX,
124125
} from "@tabler/icons-react";
125126

126127
export { uzhColors } from "./theme/uzh";

0 commit comments

Comments
 (0)