tycho-components 0.25.5 → 0.25.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,16 +34,19 @@ const toCoreFormValues = (participant) => ({
34
34
  separator: participant.separator ?? '',
35
35
  color: participant.color ?? '',
36
36
  });
37
- const toChatFormValues = (participant) => ({
38
- language: participant.language ?? '',
39
- age: participant.age ?? '',
40
- sex: participant.sex ?? '',
41
- group: participant.group ?? '',
42
- ses: participant.ses ?? '',
43
- role: participant.role ?? '',
44
- education: participant.education ?? '',
45
- custom: participant.custom ?? '',
46
- });
37
+ const toChatFormValues = (participant) => {
38
+ const chat = participant.chat ?? {};
39
+ return {
40
+ language: chat.language ?? '',
41
+ age: chat.age ?? '',
42
+ sex: chat.sex ?? '',
43
+ group: chat.group ?? '',
44
+ ses: chat.ses ?? '',
45
+ role: chat.role ?? '',
46
+ education: chat.education ?? '',
47
+ custom: chat.custom ?? '',
48
+ };
49
+ };
47
50
  export default function Participants({ document, participants, onChange, useChat, }) {
48
51
  const { t } = useTranslation('participants');
49
52
  const { dispatchMessage } = useMessageUtils();
@@ -51,10 +54,10 @@ export default function Participants({ document, participants, onChange, useChat
51
54
  const [openRemove, setOpenRemove] = useState(false);
52
55
  const [openCreate, setOpenCreate] = useState(false);
53
56
  const participantForm = useForm({
54
- defaultValues: toCoreFormValues({ order: 1, code: '', name: '' }),
57
+ defaultValues: toCoreFormValues({ order: 1, code: '', name: '', chat: {} }),
55
58
  });
56
59
  const chatForm = useForm({
57
- defaultValues: toChatFormValues({ order: 1, code: '', name: '' }),
60
+ defaultValues: toChatFormValues({ order: 1, code: '', name: '', chat: {} }),
58
61
  });
59
62
  const participantFields = useMemo(() => PARTICIPANT_FIELD_DEFS.map((field) => ({
60
63
  ...field,
@@ -67,24 +70,27 @@ export default function Participants({ document, participants, onChange, useChat
67
70
  ...field,
68
71
  name: t(`participant.field.${field.attr}`),
69
72
  })), [t]);
70
- const buildParticipantPayload = () => {
73
+ const buildParticipantPayload = (current) => {
71
74
  const coreValues = participantForm.getValues();
72
75
  const chatValues = chatForm.getValues();
73
76
  const order = typeof coreValues.order === 'string'
74
- ? Number(coreValues.order) || participant?.order || 1
77
+ ? Number(coreValues.order) || current.order || 1
75
78
  : coreValues.order;
76
79
  return {
77
- ...participant,
78
- ...chatValues,
80
+ ...current,
79
81
  ...coreValues,
80
82
  order,
83
+ chat: {
84
+ ...current.chat,
85
+ ...chatValues,
86
+ },
81
87
  };
82
88
  };
83
89
  const handleSave = () => {
84
90
  if (!participant)
85
91
  return;
86
92
  const lookupCode = participant.code;
87
- const payload = buildParticipantPayload();
93
+ const payload = buildParticipantPayload(participant);
88
94
  ParticipantService.update(document, lookupCode, payload)
89
95
  .then(() => {
90
96
  dispatchMessage({ key: 'update.success', t });
@@ -112,7 +118,7 @@ export default function Participants({ document, participants, onChange, useChat
112
118
  }, [participant, participantForm, chatForm]);
113
119
  return (_jsxs("div", { className: "participants-container", children: [_jsxs("div", { className: "header", children: [_jsx("div", { className: "title", children: t('label.title') }), _jsx("div", { className: "actions", children: _jsx(Button, { icon: "add", text: t('button.label.add'), onClick: () => setOpenCreate(true), size: "small", mode: "outlined" }) })] }), _jsx("div", { className: "body", children: participant && (_jsxs(_Fragment, { children: [_jsx(Select, { onChange: (e) => setParticipant(participants[Number(e.target.value)]), value: participant
114
120
  ? participants.findIndex((p) => p.code === participant.code)
115
- : 0, fullWidth: true, className: "select-participant", children: participants.map((el, idx) => (_jsx(MenuItem, { value: idx, children: `${el.code} - ${el.name}` }, idx))) }), _jsxs("div", { className: "fields", children: [_jsx(AppForm, { fields: participantFields, form: participantForm }), _jsx(Button, { text: t('common:button.confirm'), onClick: handleSave, size: "small", className: "save-button" })] }), useChat && (_jsxs("div", { className: "fields", children: [_jsx(AppForm, { fields: chatFields, form: chatForm }), _jsx(Button, { text: t('common:button.confirm'), onClick: handleSave, size: "small", className: "save-button" })] })), _jsx("div", { className: "footer", children: _jsx(Button, { icon: "delete", text: t('common:button.remove'), size: "small", className: "danger", onClick: () => {
121
+ : 0, fullWidth: true, className: "select-participant", children: participants.map((el, idx) => (_jsx(MenuItem, { value: idx, children: `${el.code} - ${el.name}` }, idx))) }), _jsxs("div", { className: "fields", children: [_jsx(AppForm, { fields: participantFields, form: participantForm }), useChat && (_jsx(AppForm, { fields: chatFields, form: chatForm })), _jsx(Button, { text: t('common:button.confirm'), onClick: handleSave, size: "small", className: "save-button" })] }), _jsx("div", { className: "footer", children: _jsx(Button, { icon: "delete", text: t('common:button.remove'), size: "small", className: "danger", onClick: () => {
116
122
  setParticipant(participant);
117
123
  setOpenRemove(true);
118
124
  } }) })] })) }), participant && openRemove && (_jsx(ParticipantRemove, { document: document, onChange: (list) => {
@@ -3,16 +3,9 @@ type Participant = {
3
3
  code: string;
4
4
  name: string;
5
5
  color?: string;
6
- separator?: string;
7
6
  role?: string;
8
- ses?: string;
9
- education?: string;
10
- sex?: string;
11
- custom?: string;
12
- corpus?: string;
13
- language?: string;
14
- age?: string;
15
- group?: string;
7
+ separator?: string;
8
+ chat: Record<string, string>;
16
9
  };
17
10
  export type ParticipantCreateRequest = {
18
11
  code: string;
@@ -23,9 +16,5 @@ export type ParticipantUpdateRequest = {
23
16
  code: string;
24
17
  participant: Participant;
25
18
  };
26
- export declare const EMPTY_PARTICIPANT: {
27
- order: number;
28
- code: string;
29
- name: string;
30
- };
19
+ export declare const EMPTY_PARTICIPANT: Participant;
31
20
  export default Participant;
@@ -2,4 +2,5 @@ export const EMPTY_PARTICIPANT = {
2
2
  order: 1,
3
3
  code: '',
4
4
  name: '',
5
+ chat: {},
5
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.25.5",
4
+ "version": "0.25.7",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {