@phsa.tec/design-system-react 0.1.6 → 0.1.9

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.
Files changed (217) hide show
  1. package/README.md +390 -209
  2. package/dist/index.d.mts +485 -0
  3. package/dist/index.d.ts +485 -0
  4. package/dist/index.js +4259 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +4186 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/styles.css +2534 -0
  9. package/dist/styles.css.map +1 -0
  10. package/dist/styles.d.mts +2 -0
  11. package/dist/styles.d.ts +2 -0
  12. package/package.json +46 -6
  13. package/.eslintrc.json +0 -7
  14. package/.github/workflows/deploy-storybook.yml +0 -75
  15. package/.storybook/main.ts +0 -16
  16. package/.storybook/preview.ts +0 -15
  17. package/components.json +0 -21
  18. package/jest.config.ts +0 -25
  19. package/next.config.ts +0 -7
  20. package/postcss.config.mjs +0 -8
  21. package/public/file.svg +0 -1
  22. package/public/globe.svg +0 -1
  23. package/public/next.svg +0 -1
  24. package/public/vercel.svg +0 -1
  25. package/public/window.svg +0 -1
  26. package/src/app/columns.tsx +0 -178
  27. package/src/app/favicon.ico +0 -0
  28. package/src/app/fonts/GeistMonoVF.woff +0 -0
  29. package/src/app/fonts/GeistVF.woff +0 -0
  30. package/src/app/globals.css +0 -94
  31. package/src/app/layout.tsx +0 -35
  32. package/src/app/page.tsx +0 -7
  33. package/src/components/actions/AlertDialog/AlertDialog.tsx +0 -45
  34. package/src/components/actions/AlertDialog/alert-dialog.stories.tsx +0 -21
  35. package/src/components/actions/AlertDialog/index.ts +0 -1
  36. package/src/components/actions/Button/Button.stories.ts +0 -38
  37. package/src/components/actions/Button/Button.tsx +0 -23
  38. package/src/components/actions/Button/index.ts +0 -1
  39. package/src/components/actions/Collapsible/index.ts +0 -1
  40. package/src/components/actions/Dialog/Dialog.stories.tsx +0 -70
  41. package/src/components/actions/Dialog/Dialog.tsx +0 -87
  42. package/src/components/actions/Dialog/components/DialogWithActions/index.tsx +0 -40
  43. package/src/components/actions/Dialog/index.ts +0 -1
  44. package/src/components/actions/Steps/Steps.stories.tsx +0 -25
  45. package/src/components/actions/Steps/Steps.tsx +0 -51
  46. package/src/components/actions/Steps/index.ts +0 -1
  47. package/src/components/actions/index.ts +0 -5
  48. package/src/components/dataDisplay/Avatar/Avatar.stories.tsx +0 -22
  49. package/src/components/dataDisplay/Avatar/Avatar.tsx +0 -21
  50. package/src/components/dataDisplay/Avatar/index.ts +0 -2
  51. package/src/components/dataDisplay/Badge/Badge.stories.tsx +0 -36
  52. package/src/components/dataDisplay/Badge/index.ts +0 -1
  53. package/src/components/dataDisplay/Card/Card.stories.tsx +0 -24
  54. package/src/components/dataDisplay/Card/Card.tsx +0 -34
  55. package/src/components/dataDisplay/Card/index.ts +0 -1
  56. package/src/components/dataDisplay/DataPairList/DataPairList.tsx +0 -56
  57. package/src/components/dataDisplay/DataPairList/data-pair-list.stories.tsx +0 -87
  58. package/src/components/dataDisplay/DataPairList/index.ts +0 -2
  59. package/src/components/dataDisplay/DataPairList/types.ts +0 -10
  60. package/src/components/dataDisplay/DropDownMenu/index.ts +0 -1
  61. package/src/components/dataDisplay/ErrorMessage/ErrorMessage.tsx +0 -6
  62. package/src/components/dataDisplay/ErrorMessage/index.ts +0 -1
  63. package/src/components/dataDisplay/Icon/Icon.stories.tsx +0 -21
  64. package/src/components/dataDisplay/Icon/Icon.tsx +0 -47
  65. package/src/components/dataDisplay/Icon/index.ts +0 -1
  66. package/src/components/dataDisplay/Icon/types.ts +0 -6
  67. package/src/components/dataDisplay/Label/Label.stories.tsx +0 -21
  68. package/src/components/dataDisplay/Label/Label.tsx +0 -10
  69. package/src/components/dataDisplay/Label/index.ts +0 -1
  70. package/src/components/dataDisplay/Table/Table.tsx +0 -173
  71. package/src/components/dataDisplay/Table/columns.tsx +0 -223
  72. package/src/components/dataDisplay/Table/components/DynamicTable/data-table-column-header.tsx +0 -72
  73. package/src/components/dataDisplay/Table/components/DynamicTable/data-table-pagination.tsx +0 -91
  74. package/src/components/dataDisplay/Table/components/DynamicTable/data-table-toolbar.tsx +0 -17
  75. package/src/components/dataDisplay/Table/components/DynamicTable/data-table-view-options.tsx +0 -58
  76. package/src/components/dataDisplay/Table/components/DynamicTable/data-table.stories.tsx +0 -118
  77. package/src/components/dataDisplay/Table/components/DynamicTable/index.tsx +0 -136
  78. package/src/components/dataDisplay/Table/components/DynamicTable/types.ts +0 -43
  79. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-column-header.tsx +0 -71
  80. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-faceted-filter.tsx +0 -147
  81. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-pagination.tsx +0 -97
  82. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-row-actions.tsx +0 -78
  83. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-toolbar.tsx +0 -60
  84. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-view-options.tsx +0 -59
  85. package/src/components/dataDisplay/Table/custom/CustomTable/data-table.tsx +0 -145
  86. package/src/components/dataDisplay/Table/custom/CustomTable/data.ts +0 -71
  87. package/src/components/dataDisplay/Table/custom/CustomTable/index.tsx +0 -34
  88. package/src/components/dataDisplay/Table/custom/CustomTable/schema.ts +0 -11
  89. package/src/components/dataDisplay/Table/index.ts +0 -2
  90. package/src/components/dataDisplay/Table/table.stories.tsx +0 -147
  91. package/src/components/dataDisplay/Table/types.ts +0 -15
  92. package/src/components/dataDisplay/Tabs/Tabs.stories.tsx +0 -34
  93. package/src/components/dataDisplay/Tabs/Tabs.tsx +0 -53
  94. package/src/components/dataDisplay/Tabs/index.ts +0 -1
  95. package/src/components/dataDisplay/Text/Text.stories.tsx +0 -66
  96. package/src/components/dataDisplay/Text/Text.tsx +0 -56
  97. package/src/components/dataDisplay/Text/index.ts +0 -1
  98. package/src/components/dataDisplay/index.ts +0 -8
  99. package/src/components/dataInput/Input/components/Input/Input.stories.tsx +0 -99
  100. package/src/components/dataInput/Input/components/Input/InputBase.tsx +0 -50
  101. package/src/components/dataInput/Input/components/Input/__tests__/input.test.tsx +0 -38
  102. package/src/components/dataInput/Input/components/Input/index.tsx +0 -48
  103. package/src/components/dataInput/Input/components/Input/types.ts +0 -15
  104. package/src/components/dataInput/Input/components/InputBase/index.tsx +0 -31
  105. package/src/components/dataInput/Input/components/MaskInput/__tests__/mask-input.test.tsx +0 -77
  106. package/src/components/dataInput/Input/components/MaskInput/index.ts +0 -1
  107. package/src/components/dataInput/Input/components/MaskInput/mask-input.stories.tsx +0 -85
  108. package/src/components/dataInput/Input/components/MaskInput/mask-input.tsx +0 -73
  109. package/src/components/dataInput/Input/components/MultipleInput/MultipleInput.tsx +0 -105
  110. package/src/components/dataInput/Input/components/MultipleInput/MultipleInputBase.tsx +0 -100
  111. package/src/components/dataInput/Input/components/MultipleInput/MultipleMaskInput.tsx +0 -35
  112. package/src/components/dataInput/Input/components/MultipleInput/MultipleNumberInput.tsx +0 -35
  113. package/src/components/dataInput/Input/components/MultipleInput/__tests__/multiple-input.test.tsx +0 -152
  114. package/src/components/dataInput/Input/components/MultipleInput/index.ts +0 -2
  115. package/src/components/dataInput/Input/components/MultipleInput/multiple-input.stories.tsx +0 -96
  116. package/src/components/dataInput/Input/components/NumberInput/__tests__/number-input.test.tsx +0 -175
  117. package/src/components/dataInput/Input/components/NumberInput/index.ts +0 -1
  118. package/src/components/dataInput/Input/components/NumberInput/number-input.stories.tsx +0 -76
  119. package/src/components/dataInput/Input/components/NumberInput/number-input.tsx +0 -70
  120. package/src/components/dataInput/Input/index.ts +0 -4
  121. package/src/components/dataInput/Select/MultiSelect/MultiSelect.stories.tsx +0 -119
  122. package/src/components/dataInput/Select/MultiSelect/MultiSelectBase.tsx +0 -135
  123. package/src/components/dataInput/Select/MultiSelect/index.tsx +0 -75
  124. package/src/components/dataInput/Select/Select.stories.tsx +0 -61
  125. package/src/components/dataInput/Select/Select.tsx +0 -73
  126. package/src/components/dataInput/Select/SelectBase.tsx +0 -58
  127. package/src/components/dataInput/Select/index.ts +0 -2
  128. package/src/components/dataInput/Switch/Switch.stories.tsx +0 -75
  129. package/src/components/dataInput/Switch/Switch.tsx +0 -52
  130. package/src/components/dataInput/Switch/index.ts +0 -1
  131. package/src/components/dataInput/checkbox/Checkbox.tsx +0 -57
  132. package/src/components/dataInput/checkbox/Checkbox_old.tsx +0 -58
  133. package/src/components/dataInput/checkbox/Checkout.stories.tsx +0 -62
  134. package/src/components/dataInput/checkbox/index.ts +0 -1
  135. package/src/components/dataInput/form/Form.tsx +0 -47
  136. package/src/components/dataInput/form/index.ts +0 -3
  137. package/src/components/dataInput/index.ts +0 -5
  138. package/src/components/feedback/ErrorLabel/index.tsx +0 -24
  139. package/src/components/feedback/Spinner/index.ts +0 -1
  140. package/src/components/feedback/Toast/Toast.stories.tsx +0 -45
  141. package/src/components/feedback/Toast/index.ts +0 -2
  142. package/src/components/feedback/index.ts +0 -2
  143. package/src/components/index.ts +0 -6
  144. package/src/components/layout/Crud/components/Table/index.tsx +0 -183
  145. package/src/components/layout/Crud/components/Table/types.ts +0 -15
  146. package/src/components/layout/Crud/crud.stories.tsx +0 -317
  147. package/src/components/layout/Crud/hook/useCrudLayout/index.tsx +0 -94
  148. package/src/components/layout/Crud/hook/useRequest/index.tsx +0 -156
  149. package/src/components/layout/Crud/index.tsx +0 -295
  150. package/src/components/layout/Crud/store/CrudLayoutStore.ts +0 -75
  151. package/src/components/layout/Crud/types.ts +0 -14
  152. package/src/components/layout/Drawer/CustomDrawer/index.tsx +0 -33
  153. package/src/components/layout/Drawer/Drawer.stories.tsx +0 -80
  154. package/src/components/layout/Drawer/index.ts +0 -2
  155. package/src/components/layout/PageLayout/PageLayout.stories.tsx +0 -42
  156. package/src/components/layout/PageLayout/index.tsx +0 -28
  157. package/src/components/layout/Separator/index.ts +0 -1
  158. package/src/components/layout/Sheet/Sheet.stories.tsx +0 -28
  159. package/src/components/layout/Sheet/Sheet.tsx +0 -22
  160. package/src/components/layout/Sheet/index.ts +0 -1
  161. package/src/components/layout/Sidebar/Sidebar.stories.tsx +0 -116
  162. package/src/components/layout/Sidebar/Sidebar.tsx +0 -50
  163. package/src/components/layout/Sidebar/components/app-sidebar.tsx +0 -203
  164. package/src/components/layout/Sidebar/components/footer-sidebar.tsx +0 -17
  165. package/src/components/layout/Sidebar/components/header-sidebar.tsx +0 -90
  166. package/src/components/layout/Sidebar/components/menus.tsx +0 -55
  167. package/src/components/layout/Sidebar/components/nav-projects.tsx +0 -88
  168. package/src/components/layout/Sidebar/components/nav-user.tsx +0 -114
  169. package/src/components/layout/Sidebar/components/team-switcher.tsx +0 -85
  170. package/src/components/layout/Sidebar/index.ts +0 -2
  171. package/src/components/layout/Sidebar/provider/index.tsx +0 -51
  172. package/src/components/layout/Tabs/Tabs.tsx +0 -51
  173. package/src/components/layout/Tabs/index.ts +0 -1
  174. package/src/components/layout/Tabs/tabs.stories.tsx +0 -57
  175. package/src/components/layout/index.ts +0 -6
  176. package/src/components/navigation/Breadcrumbs/Breadcrumbs.tsx +0 -66
  177. package/src/components/navigation/Breadcrumbs/index.ts +0 -2
  178. package/src/components/navigation/index.ts +0 -1
  179. package/src/components/ui/alert-dialog.tsx +0 -141
  180. package/src/components/ui/alert.tsx +0 -59
  181. package/src/components/ui/avatar.tsx +0 -50
  182. package/src/components/ui/badge.tsx +0 -40
  183. package/src/components/ui/breadcrumb.tsx +0 -115
  184. package/src/components/ui/button.tsx +0 -57
  185. package/src/components/ui/card.tsx +0 -83
  186. package/src/components/ui/checkbox.tsx +0 -34
  187. package/src/components/ui/collapsible.tsx +0 -11
  188. package/src/components/ui/command.tsx +0 -153
  189. package/src/components/ui/dialog.tsx +0 -124
  190. package/src/components/ui/drawer.tsx +0 -117
  191. package/src/components/ui/dropdown-menu.tsx +0 -201
  192. package/src/components/ui/form.tsx +0 -179
  193. package/src/components/ui/input.tsx +0 -24
  194. package/src/components/ui/label.tsx +0 -30
  195. package/src/components/ui/popover.tsx +0 -33
  196. package/src/components/ui/select.tsx +0 -161
  197. package/src/components/ui/separator.tsx +0 -31
  198. package/src/components/ui/sheet.tsx +0 -140
  199. package/src/components/ui/sidebar.tsx +0 -763
  200. package/src/components/ui/skeleton.tsx +0 -15
  201. package/src/components/ui/sonner.tsx +0 -31
  202. package/src/components/ui/spinner.tsx +0 -54
  203. package/src/components/ui/switch.tsx +0 -33
  204. package/src/components/ui/table.tsx +0 -120
  205. package/src/components/ui/tabs.tsx +0 -55
  206. package/src/components/ui/toast.tsx +0 -130
  207. package/src/components/ui/toaster.tsx +0 -35
  208. package/src/components/ui/tooltip.tsx +0 -32
  209. package/src/hooks/use-conditional-controller.tsx +0 -35
  210. package/src/hooks/use-mask.tsx +0 -116
  211. package/src/hooks/use-mobile.tsx +0 -19
  212. package/src/hooks/use-toast.ts +0 -191
  213. package/src/index.ts +0 -1
  214. package/src/introduction.mdx +0 -132
  215. package/src/lib/utils.ts +0 -6
  216. package/tailwind.config.ts +0 -83
  217. package/tsconfig.json +0 -27
@@ -1,317 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/nextjs";
2
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
- import { CrudLayout } from "./index";
4
- import { useForm } from "react-hook-form";
5
- import { Input } from "@/components/dataInput/Input/components/Input";
6
- import { Button } from "@/components/ui/button";
7
- import { ColumnDef } from "@tanstack/react-table";
8
- import { Edit, Trash2 } from "lucide-react";
9
- import { useCrudLayoutActions } from "./store/CrudLayoutStore";
10
- import { useCrudLayout } from "./hook/useCrudLayout";
11
-
12
- // Tipos de exemplo para as stories
13
- interface ExampleData {
14
- _id: string;
15
- name: string;
16
- email: string;
17
- status: string;
18
- }
19
-
20
- interface CreateData {
21
- name: string;
22
- email: string;
23
- status: string;
24
- }
25
-
26
- interface UpdateData extends CreateData {
27
- _id: string;
28
- }
29
-
30
- // Função para gerar dados aleatórios
31
- const generateMockData = (count: number): ExampleData[] => {
32
- const firstNames = [
33
- "João",
34
- "Maria",
35
- "Pedro",
36
- "Ana",
37
- "Carlos",
38
- "Lucia",
39
- "Roberto",
40
- "Fernanda",
41
- "Ricardo",
42
- "Juliana",
43
- "Marcos",
44
- "Patricia",
45
- "Antonio",
46
- "Carla",
47
- "José",
48
- "Sandra",
49
- "Paulo",
50
- "Beatriz",
51
- "Francisco",
52
- "Mariana",
53
- "Luiz",
54
- "Gabriela",
55
- "Miguel",
56
- "Larissa",
57
- "Rafael",
58
- "Camila",
59
- "Daniel",
60
- "Renata",
61
- "Felipe",
62
- "Vanessa",
63
- "Bruno",
64
- "Priscila",
65
- "Thiago",
66
- "Amanda",
67
- "Leonardo",
68
- "Bianca",
69
- "Gustavo",
70
- "Natalia",
71
- "Rodrigo",
72
- "Tatiana",
73
- "Eduardo",
74
- "Viviane",
75
- "Vinicius",
76
- "Claudia",
77
- "Matheus",
78
- "Sabrina",
79
- "Lucas",
80
- "Adriana",
81
- "Diego",
82
- "Monica",
83
- ];
84
-
85
- const lastNames = [
86
- "Silva",
87
- "Santos",
88
- "Oliveira",
89
- "Costa",
90
- "Ferreira",
91
- "Pereira",
92
- "Lima",
93
- "Alves",
94
- "Souza",
95
- "Rodrigues",
96
- "Martins",
97
- "Carvalho",
98
- "Barbosa",
99
- "Gomes",
100
- "Nascimento",
101
- "Ribeiro",
102
- "Araujo",
103
- "Dias",
104
- "Fernandes",
105
- "Morais",
106
- "Cardoso",
107
- "Campos",
108
- "Rocha",
109
- "Monteiro",
110
- "Mendes",
111
- "Freitas",
112
- "Pinto",
113
- "Cavalcanti",
114
- "Vieira",
115
- "Teixeira",
116
- "Moreira",
117
- "Correia",
118
- "Castro",
119
- "Andrade",
120
- "Nunes",
121
- "Ramos",
122
- "Lopes",
123
- "Machado",
124
- "Reis",
125
- "Moura",
126
- "Cunha",
127
- "Pires",
128
- "Farias",
129
- "Melo",
130
- "Azevedo",
131
- "Borges",
132
- "Paiva",
133
- "Coelho",
134
- "Guimaraes",
135
- "Nogueira",
136
- ];
137
-
138
- const domains = [
139
- "example.com",
140
- "test.com",
141
- "demo.com",
142
- "sample.org",
143
- "mock.net",
144
- ];
145
- const statuses = ["Ativo", "Inativo", "Pendente", "Suspenso"];
146
-
147
- const data: ExampleData[] = [];
148
-
149
- for (let i = 1; i <= count; i++) {
150
- const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
151
- const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
152
- const domain = domains[Math.floor(Math.random() * domains.length)];
153
- const status = statuses[Math.floor(Math.random() * statuses.length)];
154
-
155
- const email = `${firstName.toLowerCase()}.${lastName.toLowerCase()}@${domain}`;
156
-
157
- data.push({
158
- _id: i.toString(),
159
- name: `${firstName} ${lastName}`,
160
- email: email,
161
- status: status,
162
- });
163
- }
164
-
165
- return data;
166
- };
167
-
168
- // Dados de exemplo gerados automaticamente
169
- const mockData: ExampleData[] = generateMockData(100);
170
-
171
- // Componente de formulário de exemplo
172
- const ExampleForm = () => {
173
- return (
174
- <div className="space-y-4">
175
- <Input name="name" label="Nome" placeholder="Digite o nome" required />
176
- <Input name="email" label="Email" placeholder="Digite o email" required />
177
- <Input
178
- name="status"
179
- label="Status"
180
- placeholder="Digite o status"
181
- required
182
- />
183
- </div>
184
- );
185
- };
186
-
187
- // Create a QueryClient instance for Storybook
188
- const queryClient = new QueryClient({
189
- defaultOptions: {
190
- queries: {
191
- retry: false, // Disable retries in Storybook
192
- refetchOnWindowFocus: false, // Disable refetch on window focus
193
- },
194
- },
195
- });
196
-
197
- // Componente wrapper para usar o store
198
- const CrudWrapper = (args: any) => {
199
- const form = useForm<CreateData | UpdateData>();
200
- useCrudLayout({
201
- create: {
202
- titleModal: "Criar Usuário",
203
- submitButtonText: "Criar",
204
- descriptionModal: "Crie um novo usuário",
205
- },
206
- update: {
207
- titleModal: "Atualizar Usuário",
208
- submitButtonText: "Atualizar",
209
- descriptionModal: "Atualize os dados do usuário",
210
- },
211
- delete: {
212
- titleModal: "Deletar Usuário",
213
- submitButtonText: "Deletar",
214
- descriptionModal: "Tem certeza que deseja deletar o usuário?",
215
- },
216
- createButtonText: "Novo usuário",
217
- });
218
-
219
- // Colunas da tabela
220
- const columns: ColumnDef<ExampleData>[] = [
221
- {
222
- accessorKey: "name",
223
- header: "Nome",
224
- },
225
- {
226
- accessorKey: "email",
227
- header: "Email",
228
- },
229
- {
230
- accessorKey: "status",
231
- header: "Status",
232
- },
233
- ];
234
-
235
- // Funções de exemplo
236
- const createRequest = async (data: CreateData) => {
237
- console.log("Creating:", data);
238
- // Simula delay de requisição
239
- await new Promise((resolve) => setTimeout(resolve, 1000));
240
- return Promise.resolve();
241
- };
242
-
243
- const updateRequest = async (data: UpdateData) => {
244
- console.log("Updating:", data);
245
- // Simula delay de requisição
246
- await new Promise((resolve) => setTimeout(resolve, 1000));
247
- return Promise.resolve();
248
- };
249
-
250
- const deleteRequest = async (id: string) => {
251
- console.log("Deleting:", id);
252
- // Simula delay de requisição
253
- await new Promise((resolve) => setTimeout(resolve, 1000));
254
- return Promise.resolve();
255
- };
256
-
257
- const listRequest = async (page?: number, limit?: number) => {
258
- // Simula delay de carregamento
259
- await new Promise((resolve) => setTimeout(resolve, 500));
260
-
261
- // Implementar paginação nos dados mock
262
- const startIndex = ((page || 1) - 1) * (limit || 10);
263
- const endIndex = startIndex + (limit || 10);
264
- const paginatedData = mockData.slice(startIndex, endIndex);
265
-
266
- return Promise.resolve({
267
- data: paginatedData,
268
- total: mockData.length,
269
- });
270
- };
271
-
272
- return (
273
- <QueryClientProvider client={queryClient}>
274
- <CrudLayout
275
- {...args}
276
- columns={columns}
277
- form={form}
278
- formComponent={<ExampleForm />}
279
- createRequest={createRequest}
280
- updateRequest={updateRequest}
281
- deleteRequest={deleteRequest}
282
- listRequest={listRequest}
283
- actions={["update", "delete"]}
284
- title="Gerenciar Usuários"
285
- description="Gerencie os usuários do sistema"
286
- />
287
- </QueryClientProvider>
288
- );
289
- };
290
-
291
- const meta: Meta<typeof CrudLayout> = {
292
- title: "Layout/Crud",
293
- component: CrudLayout,
294
- tags: ["autodocs"],
295
- parameters: {
296
- layout: "fullscreen",
297
- },
298
- decorators: [
299
- (Story) => (
300
- <QueryClientProvider client={queryClient}>
301
- <div className="p-4">
302
- <Story />
303
- </div>
304
- </QueryClientProvider>
305
- ),
306
- ],
307
- };
308
-
309
- export default meta;
310
- type Story = StoryObj<typeof CrudLayout>;
311
-
312
- export const Default: Story = {
313
- render: (args) => <CrudWrapper {...args} />,
314
- args: {
315
- title: "Gerenciar Usuários",
316
- },
317
- };
@@ -1,94 +0,0 @@
1
- import { useEffect, useMemo } from "react";
2
- import {
3
- useCreateButtonText,
4
- useCrudLayoutActions,
5
- useDeleteId,
6
- useEditId,
7
- useDescriptionModal,
8
- useIsEditMode,
9
- useSubmitButtonText,
10
- useTitleModal,
11
- useOpenEditModal,
12
- } from "../../store/CrudLayoutStore";
13
-
14
- type CommonProps = {
15
- titleModal: string;
16
- descriptionModal?: string;
17
- submitButtonText: string;
18
- sendingButtonText?: string;
19
- };
20
-
21
- type UseCrudLayoutProps = {
22
- create?: CommonProps;
23
- update?: CommonProps;
24
- delete?: CommonProps;
25
- createButtonText: string;
26
- };
27
-
28
- export function useCrudLayout(props: UseCrudLayoutProps) {
29
- const deleteId = useDeleteId();
30
- const editId = useEditId();
31
- const titleModal = useTitleModal();
32
- const descriptionModal = useDescriptionModal();
33
- const submitButtonText = useSubmitButtonText();
34
- const createButtonText = useCreateButtonText();
35
- const isEditMode = useIsEditMode();
36
- const openEditModal = useOpenEditModal();
37
- const {
38
- setTitleModal,
39
- setDescriptionModal,
40
- setSubmitButtonText,
41
- setCreateButtonText,
42
- setIsEditMode,
43
- setDeleteId,
44
- setEditId,
45
- setOpenEditModal,
46
- setSendingButtonText,
47
- } = useCrudLayoutActions();
48
-
49
- const key = useMemo(() => {
50
- if (editId) return "update";
51
- if (deleteId) return "delete";
52
- return "create";
53
- }, [editId, deleteId]);
54
-
55
- useEffect(() => {
56
- const data = props[key] as CommonProps;
57
-
58
- if (data) {
59
- setTitleModal(data.titleModal);
60
- setDescriptionModal(data.descriptionModal || "");
61
- setSubmitButtonText(data.submitButtonText);
62
- setCreateButtonText(props.createButtonText);
63
- setSendingButtonText(data.sendingButtonText);
64
- }
65
- }, [
66
- props,
67
- key,
68
- setTitleModal,
69
- setDescriptionModal,
70
- setSubmitButtonText,
71
- setCreateButtonText,
72
- setSendingButtonText,
73
- deleteId,
74
- ]);
75
-
76
- return {
77
- setTitleModal,
78
- setDescriptionModal,
79
- setSubmitButtonText,
80
- setCreateButtonText,
81
- setIsEditMode,
82
- setDeleteId,
83
- setEditId,
84
- setOpenEditModal,
85
- titleModal,
86
- descriptionModal,
87
- submitButtonText,
88
- createButtonText,
89
- isEditMode,
90
- deleteId,
91
- editId,
92
- openEditModal,
93
- };
94
- }
@@ -1,156 +0,0 @@
1
- import { useCallback, useMemo } from "react";
2
- import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
- // import { ConfigResponse } from "@/service/config/types";
4
-
5
- // esse ConfigResponse
6
-
7
- export type useRequestProps<ListData, CreateData, UpdateData> = {
8
- queryKey: string;
9
- createRequest?: (data: CreateData) => Promise<ListData | void>;
10
- updateRequest?: (data: UpdateData) => Promise<ListData | void>;
11
- deleteRequest?: (id: string) => Promise<void>;
12
- listRequest: (
13
- page?: number,
14
- limit?: number
15
- ) => Promise<{ data: ListData[]; total: number }>;
16
- page: number;
17
- limit: number;
18
- };
19
-
20
- export function useRequest<
21
- ListData extends { _id: string },
22
- CreateData,
23
- UpdateData
24
- >({
25
- queryKey,
26
- updateRequest = () => Promise.resolve(),
27
- deleteRequest = () => Promise.resolve(),
28
- createRequest = () => Promise.resolve(),
29
- listRequest,
30
- page,
31
- limit,
32
- }: useRequestProps<ListData, CreateData, UpdateData>) {
33
- const queryClient = useQueryClient();
34
-
35
- const queryKeys = useMemo(() => {
36
- return [queryKey, page, limit];
37
- }, [queryKey, page, limit]);
38
-
39
- // Query para buscar configurações
40
- const {
41
- data: queryData,
42
- isLoading: isLoadingList,
43
- error: queryError,
44
- refetch,
45
- } = useQuery({
46
- queryKey: queryKeys,
47
- queryFn: () => listRequest(page, limit),
48
- staleTime: 5 * 60 * 1000, // 5 minutos
49
- });
50
-
51
- const listData = queryData?.data || [];
52
- const total = queryData?.total || 0;
53
-
54
- // Mutation para criar/atualizar configuração
55
- const {
56
- mutateAsync: createMutation,
57
- isPending: isCreating,
58
- error: createError,
59
- } = useMutation({
60
- mutationFn: createRequest,
61
- onSuccess: () => {
62
- queryClient.invalidateQueries({ queryKey: queryKeys });
63
- },
64
- });
65
-
66
- const {
67
- mutateAsync: updateMutation,
68
- isPending: isUpdating,
69
- error: updateError,
70
- } = useMutation({
71
- mutationFn: updateRequest,
72
- onSuccess: () => {
73
- queryClient.invalidateQueries({ queryKey: queryKeys });
74
- },
75
- });
76
-
77
- // Mutation para excluir configuração
78
- const {
79
- mutateAsync: deleteMutation,
80
- isPending: isDeleting,
81
- error: deleteError,
82
- } = useMutation({
83
- mutationFn: (id: string) => deleteRequest(id),
84
- onSuccess: (_, id) => {
85
- // Invalidar todas as páginas para garantir consistência
86
- queryClient.invalidateQueries({
87
- queryKey: [queryKey],
88
- exact: false,
89
- });
90
- },
91
- });
92
-
93
- const error =
94
- queryError || createError || updateError || deleteError
95
- ? (queryError || createError || updateError || deleteError) instanceof
96
- Error
97
- ? (queryError || createError || updateError || deleteError)?.message
98
- : "Erro desconhecido"
99
- : null;
100
-
101
- // Função para criar nova configuração
102
- const createActionRequest = useCallback(
103
- async (configData: CreateData) => {
104
- try {
105
- await createMutation(configData);
106
- return true;
107
- } catch (err) {
108
- console.error("Erro ao criar configuração:", err);
109
- return false;
110
- }
111
- },
112
- [createMutation]
113
- );
114
-
115
- // Função para atualizar configuração existente
116
- const updateActionRequest = useCallback(
117
- async (configData: UpdateData) => {
118
- try {
119
- await updateMutation(configData);
120
- return true;
121
- } catch (err) {
122
- console.error("Erro ao atualizar configuração:", err);
123
- return false;
124
- }
125
- },
126
- [updateMutation]
127
- );
128
-
129
- const deleteActionRequest = useCallback(
130
- async (key: string) => {
131
- try {
132
- await deleteMutation(key);
133
- return true;
134
- } catch (err) {
135
- console.error("Erro ao excluir configuração:", err);
136
- return false;
137
- }
138
- },
139
- [deleteMutation]
140
- );
141
-
142
- const refreshConfigs = useCallback(() => {
143
- return refetch();
144
- }, [refetch]);
145
-
146
- return {
147
- listData,
148
- total,
149
- isLoading: isLoadingList || isCreating || isUpdating || isDeleting,
150
- error,
151
- createActionRequest,
152
- updateActionRequest,
153
- deleteActionRequest,
154
- refreshConfigs,
155
- };
156
- }