Skip to content

Commit d947f83

Browse files
committed
feat: enhance resetting and validating entity select
1 parent 1143d5f commit d947f83

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)