code7-leia 1.0.15 → 1.0.17

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code7-leia",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "author": "code7-xlab",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.es.js",
@@ -18,7 +18,7 @@
18
18
  "scripts": {
19
19
  "dev": "vite",
20
20
  "build": "vite build",
21
- "deploy": "npm run build && npm publish"
21
+ "deploy": "npm run build && npm version patch && npm publish"
22
22
  },
23
23
  "dependencies": {
24
24
  "axios": "^1.6.7",
@@ -1,4 +1,4 @@
1
- import { useState } from 'react';
1
+ import { useState, useEffect } from "react";
2
2
  import { getLanguage } from '../../utils/getLanguage';
3
3
  import { FaPlus, FaCopy, FaEdit, FaQuestionCircle, FaTrash } from 'react-icons/fa';
4
4
  import Modal from '../Modal';
@@ -7,10 +7,10 @@ import TextArea from '../TestArea/components/TextArea';
7
7
  import Search from '../FileArea/components/Search';
8
8
  import LengthCounter from '../LengthCounter';
9
9
 
10
- import { useLeia } from '../../contexts/LeiaProvider';
10
+ import { useLeia } from "../../contexts/LeiaProvider";
11
11
 
12
- import * as S from './styles';
13
- import Tooltip from '../Tootip';
12
+ import * as S from "./styles";
13
+ import Tooltip from "../Tootip";
14
14
 
15
15
  interface Persona {
16
16
  id: number;
@@ -18,29 +18,36 @@ interface Persona {
18
18
  description: string;
19
19
  prompt: string;
20
20
  type?: string;
21
+ created_at?: string;
21
22
  }
22
23
 
23
24
  export const PersonasArea = () => {
24
25
  const { language } = useLeia();
25
26
  const t = getLanguage(language);
26
- const [_,setPersonas] = useState<Persona[]>([]);
27
27
  const { createPersona, personas, updatePersona, deletePersona } = useLeia();
28
28
 
29
- const [search, setSearch] = useState('');
29
+ const [search, setSearch] = useState("");
30
30
  const [isOpen, setIsOpen] = useState(false);
31
31
  const [editingPersona, setEditingPersona] = useState<any>(null);
32
32
  const [isDeleteOpen, setIsDeleteOpen] = useState(false);
33
33
  const [personaToDelete, setPersonaToDelete] = useState<any>(null);
34
+ const [_, setPersonas] = useState<Persona[]>([]);
35
+ const [filteredPersonas, setFilteredPersonas] = useState<any>([]);
34
36
 
35
37
  const [form, setForm] = useState({
36
- name: '',
37
- description: '',
38
- prompt: '',
38
+ name: "",
39
+ description: "",
40
+ prompt: "",
39
41
  });
40
42
 
43
+ const isFormValid =
44
+ form.name.trim() !== "" &&
45
+ form.description.trim() !== "" &&
46
+ form.prompt.trim() !== "";
47
+
41
48
  const openCreate = () => {
42
49
  setEditingPersona(null);
43
- setForm({ name: '', description: '', prompt: '' });
50
+ setForm({ name: "", description: "", prompt: "" });
44
51
  setIsOpen(true);
45
52
  };
46
53
 
@@ -65,13 +72,14 @@ export const PersonasArea = () => {
65
72
  };
66
73
 
67
74
  const handleSave = async () => {
75
+ if (!isFormValid) return;
68
76
  try {
69
77
  if (!editingPersona) {
70
78
  const payload = {
71
79
  name: form.name,
72
80
  description: form.description,
73
81
  prompt: form.prompt,
74
- type: 'persona',
82
+ type: "persona",
75
83
  };
76
84
  await createPersona(payload);
77
85
  } else {
@@ -80,7 +88,7 @@ export const PersonasArea = () => {
80
88
 
81
89
  setIsOpen(false);
82
90
  } catch (err) {
83
- console.error('Erro ao salvar persona', err);
91
+ console.error("Erro ao salvar persona", err);
84
92
  }
85
93
  };
86
94
 
@@ -95,13 +103,17 @@ export const PersonasArea = () => {
95
103
  setIsDeleteOpen(false);
96
104
  setPersonaToDelete(null);
97
105
  } catch (err) {
98
- console.error('Erro ao deletar persona', err);
106
+ console.error("Erro ao deletar persona", err);
99
107
  }
100
108
  };
101
109
 
102
- const filteredPersonas = personas?.filter((p) =>
103
- p.name.toLowerCase().includes(search.toLowerCase())
104
- );
110
+ useEffect(() => {
111
+ setFilteredPersonas(
112
+ personas?.filter((p) =>
113
+ p.name.toLowerCase().includes(search.toLowerCase()),
114
+ ),
115
+ );
116
+ }, [personas]);
105
117
 
106
118
  const ModalTitle = () => {
107
119
  return (
@@ -125,7 +137,7 @@ export const PersonasArea = () => {
125
137
  return (
126
138
  <S.Container>
127
139
  <S.Header>
128
- <div className='infos'>
140
+ <div className="infos">
129
141
  <h2>{t.personas?.title}</h2>
130
142
  <p>{t.personas?.description}</p>
131
143
  </div>
@@ -134,42 +146,47 @@ export const PersonasArea = () => {
134
146
  </button>
135
147
  </S.Header>
136
148
  <S.Search>
137
- <Search placeholder={t.search} setFiles={setPersonas} initialFiles={personas} />
149
+ <Search
150
+ placeholder={t.search}
151
+ setFiles={setFilteredPersonas}
152
+ initialFiles={personas}
153
+ />
138
154
  </S.Search>
139
155
  <S.TableContainer>
140
156
  <tbody>
141
157
  {filteredPersonas?.map((persona: any) => (
142
-
143
- <tr className = "tr-Row" key = {persona.id}>
158
+ <tr className="tr-Row" key={persona.id}>
144
159
  <td>
145
160
  <div className="info">
146
- <p><strong>{persona.name}</strong></p>
161
+ <p>
162
+ <strong>{persona.name}</strong>
163
+ </p>
147
164
  <span>{persona.description}</span>
148
165
  </div>
149
166
  </td>
150
- <td className='td-actions'>
167
+ <td className="td-actions">
151
168
  {persona.created_at && (
152
- <div className="actions">
153
- <button onClick={() => openEdit(persona)}>
154
- <FaEdit /> {t.edit}
155
- </button>
156
- <button onClick={() => openClone(persona)}>
157
- <FaCopy /> {t.clone}
158
- </button>
159
- <button className="button-delete" onClick={() => openDelete(persona)}>
160
- <FaTrash /> {t.delete}
161
- </button>
162
- </div>
163
- )}
169
+ <div className="actions">
170
+ <button onClick={() => openEdit(persona)}>
171
+ <FaEdit /> {t.edit}
172
+ </button>
173
+ <button onClick={() => openClone(persona)}>
174
+ <FaCopy /> {t.clone}
175
+ </button>
176
+ <button
177
+ className="button-delete"
178
+ onClick={() => openDelete(persona)}
179
+ >
180
+ <FaTrash /> {t.delete}
181
+ </button>
182
+ </div>
183
+ )}
164
184
  </td>
165
185
  </tr>
166
-
167
-
168
186
  ))}
169
187
  </tbody>
170
188
  </S.TableContainer>
171
189
 
172
-
173
190
  {isOpen && (
174
191
  <Modal onClose={() => setIsOpen(false)} title={<ModalTitle/>}>
175
192
  <S.InputWrapper>
@@ -182,7 +199,9 @@ export const PersonasArea = () => {
182
199
  <Input
183
200
  value={form.description}
184
201
  placeholder={t.personas?.fields.description}
185
- onChange={(value: any) => setForm({ ...form, description: value })}
202
+ onChange={(value: any) =>
203
+ setForm({ ...form, description: value })
204
+ }
186
205
  maxLength={200}
187
206
  />
188
207
  </S.InputWrapper>
@@ -196,16 +215,22 @@ export const PersonasArea = () => {
196
215
 
197
216
  <S.ModalActions>
198
217
  <button onClick={() => setIsOpen(false)}>{t.buttons.cancel}</button>
199
- <button onClick={handleSave}>{t.save}</button>
218
+ <button
219
+ onClick={handleSave}
220
+ disabled={!isFormValid}
221
+ style={{
222
+ opacity: isFormValid ? 1 : 0.5,
223
+ cursor: isFormValid ? "pointer" : "not-allowed",
224
+ }}
225
+ >
226
+ {t.save}
227
+ </button>
200
228
  </S.ModalActions>
201
229
  </Modal>
202
230
  )}
203
231
 
204
232
  {isDeleteOpen && personaToDelete && (
205
- <Modal
206
- onClose={() => setIsDeleteOpen(false)}
207
- title={t.delete}
208
- >
233
+ <Modal onClose={() => setIsDeleteOpen(false)} title={t.delete}>
209
234
  <p>
210
235
  {t.personas.modalAlert} <strong>{personaToDelete.name}</strong>?
211
236
  </p>
@@ -214,9 +239,7 @@ export const PersonasArea = () => {
214
239
  <button onClick={() => setIsDeleteOpen(false)}>
215
240
  {t.buttons.cancel}
216
241
  </button>
217
- <button onClick={confirmDelete}>
218
- {t.buttons.delete}
219
- </button>
242
+ <button onClick={confirmDelete}>{t.buttons.delete}</button>
220
243
  </S.ModalActions>
221
244
  </Modal>
222
245
  )}