= ({
};
const handleClose = (): void => {
- form.resetFields();
+ form.reset(emptyValues);
setUserOptions([]);
onCancel();
};
+ const swallowEnter = (event: React.KeyboardEvent): void => {
+ if (event.key === "Enter") event.preventDefault();
+ };
+
+ const optionsFor = (fieldName: "user_email" | "user_id", value: string | undefined): UserOption[] => {
+ const visible = selectedField === fieldName ? userOptions : [];
+ if (value == null || value === "" || visible.some((option) => option.value === value)) return visible;
+ return [{ label: value, value, user: { user_id: "", user_email: "" } }, ...visible];
+ };
+
+ const renderUserSearch = (
+ fieldName: "user_email" | "user_id",
+ placeholder: string,
+ controlProps: { id: string; value: string | undefined; onChange: (value: string | undefined) => void },
+ testId?: string,
+ ) => {
+ const items = optionsFor(fieldName, controlProps.value);
+ const selected = items.find((option) => option.value === controlProps.value) ?? null;
+ return (
+
+ {
+ controlProps.onChange(option?.value);
+ handleSelect(option);
+ }}
+ onInputValueChange={(text: string) => handleSearch(text, fieldName)}
+ isItemEqualToValue={(a: UserOption, b: UserOption) => a.value === b.value}
+ itemToStringLabel={(option: UserOption) => option.label}
+ >
+
+
+ {loading ? "Loading..." : "No results"}
+
+ {(option: UserOption) => (
+
+ {option.label}
+
+ )}
+
+
+
+
+ );
+ };
+
return (
-
-
- OR
+
+
+ {({ id, value, onChange }) =>
+ renderUserSearch("user_email", "Search by email", { id, value, onChange }, "member-email-search")
+ }
+
-
-
+ OR
-
-
-
+
+ {({ id, value, onChange }) => renderUserSearch("user_id", "Search by user ID", { id, value, onChange })}
+
-
- } loading={isSubmitting}>
- {isSubmitting ? "Adding..." : "Add Member"}
-
-
-
+
+ {({ id, value, onChange }) => (
+
+ )}
+
+
+
+
+
+
+
+
);
};