mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-21 19:59:57 +00:00
Merge pull request #789 from PBK-B/bin/fix_remove_email_setting
feat(ui): support deleting email input box auto-complete items #174
This commit is contained in:
parent
c7c89efbe7
commit
e8ed831b28
@ -1,7 +1,12 @@
|
|||||||
import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useState } from "react";
|
import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router";
|
import { Link } from "react-router";
|
||||||
import { PlusOutlined as PlusOutlinedIcon, QuestionCircleOutlined as QuestionCircleOutlinedIcon, RightOutlined as RightOutlinedIcon } from "@ant-design/icons";
|
import {
|
||||||
|
CloseOutlined as CloseOutlinedIcon,
|
||||||
|
PlusOutlined as PlusOutlinedIcon,
|
||||||
|
QuestionCircleOutlined as QuestionCircleOutlinedIcon,
|
||||||
|
RightOutlined as RightOutlinedIcon,
|
||||||
|
} from "@ant-design/icons";
|
||||||
import { useControllableValue } from "ahooks";
|
import { useControllableValue } from "ahooks";
|
||||||
import {
|
import {
|
||||||
AutoComplete,
|
AutoComplete,
|
||||||
@ -589,8 +594,7 @@ const ApplyNodeConfigForm = forwardRef<ApplyNodeConfigFormInstance, ApplyNodeCon
|
|||||||
|
|
||||||
const EmailInput = memo(
|
const EmailInput = memo(
|
||||||
({ disabled, placeholder, ...props }: { disabled?: boolean; placeholder?: string; value?: string; onChange?: (value: string) => void }) => {
|
({ disabled, placeholder, ...props }: { disabled?: boolean; placeholder?: string; value?: string; onChange?: (value: string) => void }) => {
|
||||||
const { emails, fetchEmails } = useContactEmailsStore();
|
const { emails, fetchEmails, removeEmail } = useContactEmailsStore();
|
||||||
const emailsToOptions = () => emails.map((email) => ({ label: email, value: email }));
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchEmails();
|
fetchEmails();
|
||||||
}, []);
|
}, []);
|
||||||
@ -601,24 +605,49 @@ const EmailInput = memo(
|
|||||||
trigger: "onChange",
|
trigger: "onChange",
|
||||||
});
|
});
|
||||||
|
|
||||||
const [options, setOptions] = useState<AutoCompleteProps["options"]>([]);
|
const [inputValue, setInputValue] = useState<string>();
|
||||||
useEffect(() => {
|
|
||||||
setOptions(emailsToOptions());
|
const renderOptionLabel = (email: string, removable: boolean = false) => (
|
||||||
}, [emails]);
|
<div className="flex items-center gap-2 overflow-hidden">
|
||||||
|
<span className="flex-1 overflow-hidden truncate">{email}</span>
|
||||||
|
{removable && (
|
||||||
|
<Button
|
||||||
|
color="default"
|
||||||
|
disabled={disabled}
|
||||||
|
icon={<CloseOutlinedIcon />}
|
||||||
|
size="small"
|
||||||
|
type="text"
|
||||||
|
onClick={(e) => {
|
||||||
|
removeEmail(email);
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const options = useMemo(() => {
|
||||||
|
const temp = emails.map((email) => ({
|
||||||
|
label: renderOptionLabel(email, true),
|
||||||
|
value: email,
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (!!inputValue && temp.every((option) => option.value !== inputValue)) {
|
||||||
|
temp.unshift({
|
||||||
|
label: renderOptionLabel(inputValue),
|
||||||
|
value: inputValue,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}, [emails, inputValue]);
|
||||||
|
|
||||||
const handleChange = (value: string) => {
|
const handleChange = (value: string) => {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSearch = (text: string) => {
|
const handleSearch = (value: string) => {
|
||||||
const temp = emailsToOptions();
|
setInputValue(value?.trim());
|
||||||
if (text?.trim()) {
|
|
||||||
if (temp.every((option) => option.label !== text)) {
|
|
||||||
temp.unshift({ label: text, value: text });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setOptions(temp);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -60,6 +60,7 @@ export const useContactEmailsStore = create<ContactEmailsState>((set, get) => {
|
|||||||
if (draft.includes(email)) return;
|
if (draft.includes(email)) return;
|
||||||
draft.push(email);
|
draft.push(email);
|
||||||
draft.sort();
|
draft.sort();
|
||||||
|
return draft;
|
||||||
});
|
});
|
||||||
get().setEmails(emails);
|
get().setEmails(emails);
|
||||||
},
|
},
|
||||||
@ -68,6 +69,7 @@ export const useContactEmailsStore = create<ContactEmailsState>((set, get) => {
|
|||||||
const emails = produce(get().emails, (draft) => {
|
const emails = produce(get().emails, (draft) => {
|
||||||
draft = draft.filter((e) => e !== email);
|
draft = draft.filter((e) => e !== email);
|
||||||
draft.sort();
|
draft.sort();
|
||||||
|
return draft;
|
||||||
});
|
});
|
||||||
get().setEmails(emails);
|
get().setEmails(emails);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user