Skip to content

Commit 8eda4cf

Browse files
committed
crm: make it possible to edit the tags of one single user
- note: you MUST click reload to see the changes
1 parent 9c4130a commit 8eda4cf

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

src/packages/frontend/frame-editors/crm-editor/fields/string-tags.tsx

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ This is much less complicated than the normal tags that map
44
to integers in the CRM. These are used at least for
55
accounts for users to indicate their interests.
66
*/
7-
import { Tag } from "antd";
8-
7+
import { Input, Tag } from "antd";
98
import { render } from "./register";
9+
import { useEffect, useRef, useState } from "react";
10+
import { useEditableContext } from "./context";
1011

11-
render({ type: "string-tags" }, ({ field, obj }) => {
12+
render({ type: "string-tags", editable: false }, ({ field, obj }) => {
1213
const tags = obj[field];
1314
if (tags == null) return null;
1415
return (
@@ -19,3 +20,52 @@ render({ type: "string-tags" }, ({ field, obj }) => {
1920
</div>
2021
);
2122
});
23+
24+
render({ type: "string-tags", editable: true }, ({ field, obj, spec }) => {
25+
const ref = useRef<any>(undefined);
26+
const { save, saving, counter, edit, error, ClickToEdit } =
27+
useEditableContext<string>(field);
28+
const [value, setValue] = useState<string>(obj[field]?.join(",") ?? "");
29+
useEffect(() => {
30+
setValue(obj[field]);
31+
}, [counter, obj[field]]);
32+
33+
if (spec.type != "string-tags" || !spec.editable) {
34+
throw Error("bug");
35+
}
36+
if (!edit) {
37+
const tags = obj[field];
38+
return (
39+
<ClickToEdit empty={!tags || tags.length == 0}>
40+
<div style={{ lineHeight: "2em", display: "inline-block" }}>
41+
{tags?.map((value) => (
42+
<Tag key={value}>{value}</Tag>
43+
))}
44+
</div>
45+
</ClickToEdit>
46+
);
47+
}
48+
return (
49+
<>
50+
<Input
51+
style={{ width: "100%" }}
52+
disabled={saving}
53+
ref={ref}
54+
autoFocus
55+
value={value}
56+
onChange={(e) => {
57+
setValue(e.target.value);
58+
}}
59+
onBlur={() => {
60+
setValue(ref.current.input.value);
61+
save(obj, ref.current.input.value.split(","));
62+
}}
63+
onPressEnter={() => {
64+
setValue(ref.current.input.value);
65+
save(obj, ref.current.input.value.split(","));
66+
}}
67+
/>
68+
{error}
69+
</>
70+
);
71+
});

src/packages/util/db-schema/accounts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ Table({
720720
banned: true,
721721
unlisted: true,
722722
notes: true,
723+
tags: true,
723724
salesloft_id: true,
724725
purchase_closing_day: true,
725726
min_balance: true, // admins can set this

0 commit comments

Comments
 (0)