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

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 (213) 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/package.json +46 -6
  9. package/.eslintrc.json +0 -7
  10. package/.github/workflows/deploy-storybook.yml +0 -75
  11. package/.storybook/main.ts +0 -16
  12. package/.storybook/preview.ts +0 -15
  13. package/components.json +0 -21
  14. package/jest.config.ts +0 -25
  15. package/next.config.ts +0 -7
  16. package/postcss.config.mjs +0 -8
  17. package/public/file.svg +0 -1
  18. package/public/globe.svg +0 -1
  19. package/public/next.svg +0 -1
  20. package/public/vercel.svg +0 -1
  21. package/public/window.svg +0 -1
  22. package/src/app/columns.tsx +0 -178
  23. package/src/app/favicon.ico +0 -0
  24. package/src/app/fonts/GeistMonoVF.woff +0 -0
  25. package/src/app/fonts/GeistVF.woff +0 -0
  26. package/src/app/globals.css +0 -94
  27. package/src/app/layout.tsx +0 -35
  28. package/src/app/page.tsx +0 -7
  29. package/src/components/actions/AlertDialog/AlertDialog.tsx +0 -45
  30. package/src/components/actions/AlertDialog/alert-dialog.stories.tsx +0 -21
  31. package/src/components/actions/AlertDialog/index.ts +0 -1
  32. package/src/components/actions/Button/Button.stories.ts +0 -38
  33. package/src/components/actions/Button/Button.tsx +0 -23
  34. package/src/components/actions/Button/index.ts +0 -1
  35. package/src/components/actions/Collapsible/index.ts +0 -1
  36. package/src/components/actions/Dialog/Dialog.stories.tsx +0 -70
  37. package/src/components/actions/Dialog/Dialog.tsx +0 -87
  38. package/src/components/actions/Dialog/components/DialogWithActions/index.tsx +0 -40
  39. package/src/components/actions/Dialog/index.ts +0 -1
  40. package/src/components/actions/Steps/Steps.stories.tsx +0 -25
  41. package/src/components/actions/Steps/Steps.tsx +0 -51
  42. package/src/components/actions/Steps/index.ts +0 -1
  43. package/src/components/actions/index.ts +0 -5
  44. package/src/components/dataDisplay/Avatar/Avatar.stories.tsx +0 -22
  45. package/src/components/dataDisplay/Avatar/Avatar.tsx +0 -21
  46. package/src/components/dataDisplay/Avatar/index.ts +0 -2
  47. package/src/components/dataDisplay/Badge/Badge.stories.tsx +0 -36
  48. package/src/components/dataDisplay/Badge/index.ts +0 -1
  49. package/src/components/dataDisplay/Card/Card.stories.tsx +0 -24
  50. package/src/components/dataDisplay/Card/Card.tsx +0 -34
  51. package/src/components/dataDisplay/Card/index.ts +0 -1
  52. package/src/components/dataDisplay/DataPairList/DataPairList.tsx +0 -56
  53. package/src/components/dataDisplay/DataPairList/data-pair-list.stories.tsx +0 -87
  54. package/src/components/dataDisplay/DataPairList/index.ts +0 -2
  55. package/src/components/dataDisplay/DataPairList/types.ts +0 -10
  56. package/src/components/dataDisplay/DropDownMenu/index.ts +0 -1
  57. package/src/components/dataDisplay/ErrorMessage/ErrorMessage.tsx +0 -6
  58. package/src/components/dataDisplay/ErrorMessage/index.ts +0 -1
  59. package/src/components/dataDisplay/Icon/Icon.stories.tsx +0 -21
  60. package/src/components/dataDisplay/Icon/Icon.tsx +0 -47
  61. package/src/components/dataDisplay/Icon/index.ts +0 -1
  62. package/src/components/dataDisplay/Icon/types.ts +0 -6
  63. package/src/components/dataDisplay/Label/Label.stories.tsx +0 -21
  64. package/src/components/dataDisplay/Label/Label.tsx +0 -10
  65. package/src/components/dataDisplay/Label/index.ts +0 -1
  66. package/src/components/dataDisplay/Table/Table.tsx +0 -173
  67. package/src/components/dataDisplay/Table/columns.tsx +0 -223
  68. package/src/components/dataDisplay/Table/components/DynamicTable/data-table-column-header.tsx +0 -72
  69. package/src/components/dataDisplay/Table/components/DynamicTable/data-table-pagination.tsx +0 -91
  70. package/src/components/dataDisplay/Table/components/DynamicTable/data-table-toolbar.tsx +0 -17
  71. package/src/components/dataDisplay/Table/components/DynamicTable/data-table-view-options.tsx +0 -58
  72. package/src/components/dataDisplay/Table/components/DynamicTable/data-table.stories.tsx +0 -118
  73. package/src/components/dataDisplay/Table/components/DynamicTable/index.tsx +0 -136
  74. package/src/components/dataDisplay/Table/components/DynamicTable/types.ts +0 -43
  75. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-column-header.tsx +0 -71
  76. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-faceted-filter.tsx +0 -147
  77. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-pagination.tsx +0 -97
  78. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-row-actions.tsx +0 -78
  79. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-toolbar.tsx +0 -60
  80. package/src/components/dataDisplay/Table/custom/CustomTable/data-table-view-options.tsx +0 -59
  81. package/src/components/dataDisplay/Table/custom/CustomTable/data-table.tsx +0 -145
  82. package/src/components/dataDisplay/Table/custom/CustomTable/data.ts +0 -71
  83. package/src/components/dataDisplay/Table/custom/CustomTable/index.tsx +0 -34
  84. package/src/components/dataDisplay/Table/custom/CustomTable/schema.ts +0 -11
  85. package/src/components/dataDisplay/Table/index.ts +0 -2
  86. package/src/components/dataDisplay/Table/table.stories.tsx +0 -147
  87. package/src/components/dataDisplay/Table/types.ts +0 -15
  88. package/src/components/dataDisplay/Tabs/Tabs.stories.tsx +0 -34
  89. package/src/components/dataDisplay/Tabs/Tabs.tsx +0 -53
  90. package/src/components/dataDisplay/Tabs/index.ts +0 -1
  91. package/src/components/dataDisplay/Text/Text.stories.tsx +0 -66
  92. package/src/components/dataDisplay/Text/Text.tsx +0 -56
  93. package/src/components/dataDisplay/Text/index.ts +0 -1
  94. package/src/components/dataDisplay/index.ts +0 -8
  95. package/src/components/dataInput/Input/components/Input/Input.stories.tsx +0 -99
  96. package/src/components/dataInput/Input/components/Input/InputBase.tsx +0 -50
  97. package/src/components/dataInput/Input/components/Input/__tests__/input.test.tsx +0 -38
  98. package/src/components/dataInput/Input/components/Input/index.tsx +0 -48
  99. package/src/components/dataInput/Input/components/Input/types.ts +0 -15
  100. package/src/components/dataInput/Input/components/InputBase/index.tsx +0 -31
  101. package/src/components/dataInput/Input/components/MaskInput/__tests__/mask-input.test.tsx +0 -77
  102. package/src/components/dataInput/Input/components/MaskInput/index.ts +0 -1
  103. package/src/components/dataInput/Input/components/MaskInput/mask-input.stories.tsx +0 -85
  104. package/src/components/dataInput/Input/components/MaskInput/mask-input.tsx +0 -73
  105. package/src/components/dataInput/Input/components/MultipleInput/MultipleInput.tsx +0 -105
  106. package/src/components/dataInput/Input/components/MultipleInput/MultipleInputBase.tsx +0 -100
  107. package/src/components/dataInput/Input/components/MultipleInput/MultipleMaskInput.tsx +0 -35
  108. package/src/components/dataInput/Input/components/MultipleInput/MultipleNumberInput.tsx +0 -35
  109. package/src/components/dataInput/Input/components/MultipleInput/__tests__/multiple-input.test.tsx +0 -152
  110. package/src/components/dataInput/Input/components/MultipleInput/index.ts +0 -2
  111. package/src/components/dataInput/Input/components/MultipleInput/multiple-input.stories.tsx +0 -96
  112. package/src/components/dataInput/Input/components/NumberInput/__tests__/number-input.test.tsx +0 -175
  113. package/src/components/dataInput/Input/components/NumberInput/index.ts +0 -1
  114. package/src/components/dataInput/Input/components/NumberInput/number-input.stories.tsx +0 -76
  115. package/src/components/dataInput/Input/components/NumberInput/number-input.tsx +0 -70
  116. package/src/components/dataInput/Input/index.ts +0 -4
  117. package/src/components/dataInput/Select/MultiSelect/MultiSelect.stories.tsx +0 -119
  118. package/src/components/dataInput/Select/MultiSelect/MultiSelectBase.tsx +0 -135
  119. package/src/components/dataInput/Select/MultiSelect/index.tsx +0 -75
  120. package/src/components/dataInput/Select/Select.stories.tsx +0 -61
  121. package/src/components/dataInput/Select/Select.tsx +0 -73
  122. package/src/components/dataInput/Select/SelectBase.tsx +0 -58
  123. package/src/components/dataInput/Select/index.ts +0 -2
  124. package/src/components/dataInput/Switch/Switch.stories.tsx +0 -75
  125. package/src/components/dataInput/Switch/Switch.tsx +0 -52
  126. package/src/components/dataInput/Switch/index.ts +0 -1
  127. package/src/components/dataInput/checkbox/Checkbox.tsx +0 -57
  128. package/src/components/dataInput/checkbox/Checkbox_old.tsx +0 -58
  129. package/src/components/dataInput/checkbox/Checkout.stories.tsx +0 -62
  130. package/src/components/dataInput/checkbox/index.ts +0 -1
  131. package/src/components/dataInput/form/Form.tsx +0 -47
  132. package/src/components/dataInput/form/index.ts +0 -3
  133. package/src/components/dataInput/index.ts +0 -5
  134. package/src/components/feedback/ErrorLabel/index.tsx +0 -24
  135. package/src/components/feedback/Spinner/index.ts +0 -1
  136. package/src/components/feedback/Toast/Toast.stories.tsx +0 -45
  137. package/src/components/feedback/Toast/index.ts +0 -2
  138. package/src/components/feedback/index.ts +0 -2
  139. package/src/components/index.ts +0 -6
  140. package/src/components/layout/Crud/components/Table/index.tsx +0 -183
  141. package/src/components/layout/Crud/components/Table/types.ts +0 -15
  142. package/src/components/layout/Crud/crud.stories.tsx +0 -317
  143. package/src/components/layout/Crud/hook/useCrudLayout/index.tsx +0 -94
  144. package/src/components/layout/Crud/hook/useRequest/index.tsx +0 -156
  145. package/src/components/layout/Crud/index.tsx +0 -295
  146. package/src/components/layout/Crud/store/CrudLayoutStore.ts +0 -75
  147. package/src/components/layout/Crud/types.ts +0 -14
  148. package/src/components/layout/Drawer/CustomDrawer/index.tsx +0 -33
  149. package/src/components/layout/Drawer/Drawer.stories.tsx +0 -80
  150. package/src/components/layout/Drawer/index.ts +0 -2
  151. package/src/components/layout/PageLayout/PageLayout.stories.tsx +0 -42
  152. package/src/components/layout/PageLayout/index.tsx +0 -28
  153. package/src/components/layout/Separator/index.ts +0 -1
  154. package/src/components/layout/Sheet/Sheet.stories.tsx +0 -28
  155. package/src/components/layout/Sheet/Sheet.tsx +0 -22
  156. package/src/components/layout/Sheet/index.ts +0 -1
  157. package/src/components/layout/Sidebar/Sidebar.stories.tsx +0 -116
  158. package/src/components/layout/Sidebar/Sidebar.tsx +0 -50
  159. package/src/components/layout/Sidebar/components/app-sidebar.tsx +0 -203
  160. package/src/components/layout/Sidebar/components/footer-sidebar.tsx +0 -17
  161. package/src/components/layout/Sidebar/components/header-sidebar.tsx +0 -90
  162. package/src/components/layout/Sidebar/components/menus.tsx +0 -55
  163. package/src/components/layout/Sidebar/components/nav-projects.tsx +0 -88
  164. package/src/components/layout/Sidebar/components/nav-user.tsx +0 -114
  165. package/src/components/layout/Sidebar/components/team-switcher.tsx +0 -85
  166. package/src/components/layout/Sidebar/index.ts +0 -2
  167. package/src/components/layout/Sidebar/provider/index.tsx +0 -51
  168. package/src/components/layout/Tabs/Tabs.tsx +0 -51
  169. package/src/components/layout/Tabs/index.ts +0 -1
  170. package/src/components/layout/Tabs/tabs.stories.tsx +0 -57
  171. package/src/components/layout/index.ts +0 -6
  172. package/src/components/navigation/Breadcrumbs/Breadcrumbs.tsx +0 -66
  173. package/src/components/navigation/Breadcrumbs/index.ts +0 -2
  174. package/src/components/navigation/index.ts +0 -1
  175. package/src/components/ui/alert-dialog.tsx +0 -141
  176. package/src/components/ui/alert.tsx +0 -59
  177. package/src/components/ui/avatar.tsx +0 -50
  178. package/src/components/ui/badge.tsx +0 -40
  179. package/src/components/ui/breadcrumb.tsx +0 -115
  180. package/src/components/ui/button.tsx +0 -57
  181. package/src/components/ui/card.tsx +0 -83
  182. package/src/components/ui/checkbox.tsx +0 -34
  183. package/src/components/ui/collapsible.tsx +0 -11
  184. package/src/components/ui/command.tsx +0 -153
  185. package/src/components/ui/dialog.tsx +0 -124
  186. package/src/components/ui/drawer.tsx +0 -117
  187. package/src/components/ui/dropdown-menu.tsx +0 -201
  188. package/src/components/ui/form.tsx +0 -179
  189. package/src/components/ui/input.tsx +0 -24
  190. package/src/components/ui/label.tsx +0 -30
  191. package/src/components/ui/popover.tsx +0 -33
  192. package/src/components/ui/select.tsx +0 -161
  193. package/src/components/ui/separator.tsx +0 -31
  194. package/src/components/ui/sheet.tsx +0 -140
  195. package/src/components/ui/sidebar.tsx +0 -763
  196. package/src/components/ui/skeleton.tsx +0 -15
  197. package/src/components/ui/sonner.tsx +0 -31
  198. package/src/components/ui/spinner.tsx +0 -54
  199. package/src/components/ui/switch.tsx +0 -33
  200. package/src/components/ui/table.tsx +0 -120
  201. package/src/components/ui/tabs.tsx +0 -55
  202. package/src/components/ui/toast.tsx +0 -130
  203. package/src/components/ui/toaster.tsx +0 -35
  204. package/src/components/ui/tooltip.tsx +0 -32
  205. package/src/hooks/use-conditional-controller.tsx +0 -35
  206. package/src/hooks/use-mask.tsx +0 -116
  207. package/src/hooks/use-mobile.tsx +0 -19
  208. package/src/hooks/use-toast.ts +0 -191
  209. package/src/index.ts +0 -1
  210. package/src/introduction.mdx +0 -132
  211. package/src/lib/utils.ts +0 -6
  212. package/tailwind.config.ts +0 -83
  213. package/tsconfig.json +0 -27
@@ -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
- }
@@ -1,295 +0,0 @@
1
- import { AlertCircle, Edit, Plus, Trash2 } from "lucide-react";
2
- import { Table } from "./components/Table";
3
- import { CrudLayoutProps } from "./types";
4
- import { Button } from "@/components/ui/button";
5
- import { useCallback, useEffect, useMemo, useState } from "react";
6
- import { Form } from "@/components/ui/form";
7
- import {
8
- Dialog,
9
- DialogHeader,
10
- DialogContent,
11
- DialogTitle,
12
- DialogDescription,
13
- DialogFooter,
14
- } from "@/components/ui/dialog";
15
- import {
16
- useTitleModal,
17
- useDescriptionModal,
18
- useSubmitButtonText,
19
- useCreateButtonText,
20
- useCrudLayoutActions,
21
- useOpenEditModal,
22
- useDeleteId,
23
- useEditId,
24
- useSendingButtonText,
25
- } from "./store/CrudLayoutStore";
26
- import {
27
- AlertDialog,
28
- AlertDialogAction,
29
- AlertDialogCancel,
30
- AlertDialogContent,
31
- AlertDialogDescription,
32
- AlertDialogFooter,
33
- AlertDialogHeader,
34
- AlertDialogTitle,
35
- } from "@/components/ui/alert-dialog";
36
- import { useRequest } from "./hook/useRequest";
37
- import { Alert, AlertDescription } from "@/components/ui/alert";
38
- import { toast } from "sonner";
39
-
40
- export const CrudLayout = <
41
- ListData extends { _id: string },
42
- CreateData,
43
- UpdateData
44
- >({
45
- columns,
46
- title,
47
- createRequest,
48
- updateRequest,
49
- deleteRequest,
50
- listRequest = () => Promise.resolve({ data: [], total: 0 }),
51
- formComponent,
52
- actions = [],
53
- form,
54
- }: CrudLayoutProps<ListData, CreateData, UpdateData>) => {
55
- const [isModalOpen, setIsModalOpen] = useState(false);
56
- const [modalMode, setModalMode] = useState<"create" | "edit">("create");
57
- const [page, setPage] = useState(1);
58
- const [limit, setLimit] = useState(10);
59
-
60
- const titleModal = useTitleModal();
61
- const descriptionModal = useDescriptionModal();
62
- const submitButtonText = useSubmitButtonText();
63
- const createButtonText = useCreateButtonText();
64
- const sendingButtonText = useSendingButtonText();
65
- const deleteId = useDeleteId();
66
- const editId = useEditId();
67
- const openEditModal = useOpenEditModal();
68
- const { setDeleteId, setOpenEditModal, setEditId } = useCrudLayoutActions();
69
-
70
- const isEditMode = useMemo(() => modalMode === "edit", [modalMode]);
71
-
72
- const {
73
- listData,
74
- total,
75
- error,
76
- createActionRequest,
77
- updateActionRequest,
78
- deleteActionRequest,
79
- isLoading,
80
- } = useRequest({
81
- queryKey: "configs",
82
- createRequest,
83
- updateRequest,
84
- deleteRequest,
85
- listRequest,
86
- page,
87
- limit,
88
- });
89
-
90
- useEffect(() => {
91
- if (openEditModal && editId) {
92
- const itemToEdit = listData.find((item: ListData) => item._id === editId);
93
- if (itemToEdit) {
94
- form.reset(itemToEdit);
95
- setModalMode("edit");
96
- setIsModalOpen(true);
97
- setOpenEditModal(false);
98
- }
99
- }
100
- }, [editId, form, listData, openEditModal, setOpenEditModal]);
101
-
102
- const resetForm = useCallback(() => {
103
- form.reset({});
104
- const formValues = form.getValues();
105
- Object.keys(formValues).forEach((key) => {
106
- form.setValue(key, "");
107
- });
108
- }, [form]);
109
-
110
- const customColumns = useMemo(() => {
111
- const editButton = actions.includes("update") && {
112
- id: "actions",
113
- header: "Ações",
114
- cell: ({ row }) => {
115
- const data = row.original;
116
- return (
117
- <div className="flex gap-2">
118
- {actions.includes("update") && (
119
- <Button
120
- variant="outline"
121
- size="sm"
122
- onClick={() => {
123
- setEditId(data._id);
124
- setOpenEditModal(true);
125
- }}
126
- >
127
- <Edit className="h-4 w-4" />
128
- </Button>
129
- )}
130
- {actions.includes("delete") && (
131
- <Button
132
- variant="outline"
133
- size="sm"
134
- onClick={() => setDeleteId(data._id)}
135
- >
136
- <Trash2 className="h-4 w-4" />
137
- </Button>
138
- )}
139
- </div>
140
- );
141
- },
142
- };
143
-
144
- const data = [...columns];
145
-
146
- if (editButton) data.push(editButton);
147
-
148
- return data;
149
- }, [columns, actions, setEditId, setOpenEditModal, setDeleteId]);
150
-
151
- const closeModal = useCallback(() => {
152
- setIsModalOpen(false);
153
- setModalMode("create");
154
- setEditId(null);
155
- resetForm();
156
- }, [setEditId, resetForm]);
157
-
158
- const onSubmit = useCallback(
159
- async (data: CreateData | UpdateData) => {
160
- try {
161
- let success;
162
-
163
- if (isEditMode) {
164
- success = await updateActionRequest(data as UpdateData);
165
- if (success) {
166
- toast.success("Configuração atualizada");
167
- }
168
- } else {
169
- success = await createActionRequest(data as CreateData);
170
- if (success) {
171
- toast.success("Configuração criada");
172
- }
173
- }
174
-
175
- if (success) {
176
- closeModal();
177
- }
178
- } catch (error) {
179
- console.error("Erro ao salvar:", error);
180
- toast.error("Erro ao salvar configuração");
181
- }
182
- },
183
- [createActionRequest, updateActionRequest, isEditMode, closeModal]
184
- );
185
-
186
- const onClickCreate = useCallback(() => {
187
- resetForm();
188
- setModalMode("create");
189
- setEditId(null);
190
- setIsModalOpen(true);
191
- }, [setEditId, resetForm]);
192
-
193
- const onDeleteData = useCallback(
194
- async (dataId: string) => {
195
- const success = await deleteActionRequest(dataId);
196
- if (success) {
197
- toast.success("Configuração deletada com sucesso");
198
- setDeleteId(null);
199
- }
200
- },
201
- [deleteActionRequest, setDeleteId]
202
- );
203
-
204
- const handleModalOpenChange = useCallback(
205
- (isOpen: boolean) => {
206
- if (!isOpen) {
207
- closeModal();
208
- }
209
- },
210
- [closeModal]
211
- );
212
-
213
- const handlePageChange = useCallback((newPage: number) => {
214
- setPage(newPage);
215
- }, []);
216
-
217
- const handleLimitChange = useCallback((newLimit: number) => {
218
- setLimit(newLimit);
219
- setPage(1); // Reset to first page when changing limit
220
- }, []);
221
-
222
- return (
223
- <div className="container mx-auto p-4 space-y-6 bg-white rounded-md">
224
- <div className="flex justify-between items-center md:flex-row flex-col gap-4">
225
- <h1 className="text-2xl font-bold">{title}</h1>
226
- <Button onClick={onClickCreate} className="w-full md:w-auto">
227
- <Plus className="mr-2 h-4 w-4" /> {createButtonText}
228
- </Button>
229
- </div>
230
-
231
- <Dialog open={isModalOpen} onOpenChange={handleModalOpenChange}>
232
- <DialogContent>
233
- <DialogHeader>
234
- <DialogTitle>{titleModal}</DialogTitle>
235
- <DialogDescription>{descriptionModal}</DialogDescription>
236
- </DialogHeader>
237
- <Form {...form}>
238
- <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
239
- {formComponent}
240
- <DialogFooter>
241
- <Button type="submit" disabled={isLoading}>
242
- {isLoading ? sendingButtonText : submitButtonText}
243
- </Button>
244
- </DialogFooter>
245
- </form>
246
- </Form>
247
- </DialogContent>
248
- </Dialog>
249
-
250
- {error && (
251
- <Alert variant="destructive">
252
- <AlertCircle className="h-4 w-4" />
253
- <AlertDescription>{error}</AlertDescription>
254
- </Alert>
255
- )}
256
-
257
- <Table<ListData>
258
- data={listData}
259
- columns={customColumns}
260
- isLoading={isLoading}
261
- pagination={{
262
- page,
263
- limit,
264
- total,
265
- onPageChange: handlePageChange,
266
- onLimitChange: handleLimitChange,
267
- }}
268
- />
269
- <AlertDialog
270
- open={!!deleteId}
271
- onOpenChange={(open) => {
272
- if (!open) {
273
- setDeleteId(null);
274
- }
275
- }}
276
- >
277
- <AlertDialogContent>
278
- <AlertDialogHeader>
279
- <AlertDialogTitle>{titleModal}</AlertDialogTitle>
280
- <AlertDialogDescription>{descriptionModal}</AlertDialogDescription>
281
- </AlertDialogHeader>
282
- <AlertDialogFooter>
283
- <AlertDialogCancel>Cancelar</AlertDialogCancel>
284
- <AlertDialogAction
285
- onClick={() => onDeleteData(deleteId as string)}
286
- className="bg-red-600 hover:bg-red-700"
287
- >
288
- {isLoading ? sendingButtonText : "Excluir"}
289
- </AlertDialogAction>
290
- </AlertDialogFooter>
291
- </AlertDialogContent>
292
- </AlertDialog>
293
- </div>
294
- );
295
- };
@@ -1,75 +0,0 @@
1
- import { create } from "zustand";
2
-
3
- export type CrudLayoutStore = {
4
- titleModal?: string;
5
- descriptionModal?: string;
6
- submitButtonText?: string;
7
- createButtonText?: string;
8
- isEditMode: boolean;
9
- deleteId: string | null;
10
- editId: string | null;
11
- openEditModal: boolean;
12
- sendingButtonText?: string;
13
- actions: {
14
- setTitleModal: (title: string) => void;
15
- setDescriptionModal: (description: string) => void;
16
- setSubmitButtonText: (text: string) => void;
17
- setCreateButtonText: (text: string) => void;
18
- setIsEditMode: (isEditMode: boolean) => void;
19
- setDeleteId: (id: string | null) => void;
20
- setEditId: (id: string | null) => void;
21
- setOpenEditModal: (open: boolean) => void;
22
- setSendingButtonText: (text?: string) => void;
23
- };
24
- };
25
-
26
- export const useCrudLayoutStore = create<CrudLayoutStore>((set) => ({
27
- titleModal: "",
28
- descriptionModal: "",
29
- submitButtonText: "Salvar",
30
- createButtonText: "Criar",
31
- isEditMode: false,
32
- deleteId: null,
33
- editId: null,
34
- openEditModal: false,
35
- actions: {
36
- setTitleModal: (title) => set({ titleModal: title }),
37
- setDescriptionModal: (description) =>
38
- set({ descriptionModal: description }),
39
- setSubmitButtonText: (text) => set({ submitButtonText: text }),
40
- setCreateButtonText: (text) => set({ createButtonText: text }),
41
- setIsEditMode: (isEditMode) => set({ isEditMode }),
42
- setDeleteId: (id) => set({ deleteId: id }),
43
- setEditId: (id) => set({ editId: id }),
44
- setOpenEditModal: (open) => set({ openEditModal: open }),
45
- setSendingButtonText: (text) => set({ sendingButtonText: text }),
46
- },
47
- }));
48
-
49
- export const useCrudLayoutActions = () =>
50
- useCrudLayoutStore((state) => state.actions);
51
-
52
- export const useTitleModal = () =>
53
- useCrudLayoutStore((state) => state.titleModal);
54
-
55
- export const useDescriptionModal = () =>
56
- useCrudLayoutStore((state) => state.descriptionModal);
57
-
58
- export const useSubmitButtonText = () =>
59
- useCrudLayoutStore((state) => state.submitButtonText);
60
-
61
- export const useCreateButtonText = () =>
62
- useCrudLayoutStore((state) => state.createButtonText);
63
-
64
- export const useIsEditMode = () =>
65
- useCrudLayoutStore((state) => state.isEditMode);
66
-
67
- export const useDeleteId = () => useCrudLayoutStore((state) => state.deleteId);
68
-
69
- export const useEditId = () => useCrudLayoutStore((state) => state.editId);
70
-
71
- export const useOpenEditModal = () =>
72
- useCrudLayoutStore((state) => state.openEditModal);
73
-
74
- export const useSendingButtonText = () =>
75
- useCrudLayoutStore((state) => state.sendingButtonText);
@@ -1,14 +0,0 @@
1
- import { ColumnDef } from "@tanstack/react-table";
2
-
3
- export type CrudLayoutProps<ListData, CreateData, UpdateData> = {
4
- columns: ColumnDef<ListData>[];
5
- title: string;
6
- listRequest?: () => Promise<ListData[]>;
7
- createRequest?: (data?: CreateData) => Promise<ListData>;
8
- updateRequest?: (data?: UpdateData) => Promise<ListData>;
9
- deleteRequest?: (key: string) => Promise<void>;
10
- formComponent: React.ReactNode;
11
-
12
- form: any;
13
- actions?: ["create", "update", "delete"];
14
- };
@@ -1,33 +0,0 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import { Minus, Plus } from "lucide-react";
5
- // import { Bar, BarChart, ResponsiveContainer } from "recharts";
6
-
7
- import { Button } from "../../../actions";
8
- import {
9
- Drawer,
10
- DrawerClose,
11
- DrawerContent,
12
- DrawerDescription,
13
- DrawerFooter,
14
- DrawerHeader,
15
- DrawerProps,
16
- DrawerTitle,
17
- DrawerTrigger,
18
- } from "../../Drawer";
19
-
20
- export type CustomDrawerProps = DrawerProps & {
21
- className?: string;
22
- };
23
-
24
- export function CustomDrawer({ className, ...props }: CustomDrawerProps) {
25
- return (
26
- <Drawer {...props}>
27
- {/* <DrawerTrigger asChild>
28
- <Button variant="outline">Open Drawer</Button>
29
- </DrawerTrigger> */}
30
- <DrawerContent className={className}>{props.children}</DrawerContent>
31
- </Drawer>
32
- );
33
- }
@@ -1,80 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/nextjs";
2
-
3
- import { Button } from "../../actions/Button";
4
-
5
- import {
6
- Drawer,
7
- DrawerClose,
8
- DrawerContent,
9
- DrawerDescription,
10
- DrawerFooter,
11
- DrawerHeader,
12
- DrawerTitle,
13
- DrawerTrigger,
14
- CustomDrawer as CustomDrawerComponent,
15
- CustomDrawerProps,
16
- } from "./index";
17
-
18
- const meta = {
19
- title: "DataDisplay/Drawer",
20
- render: (args) => {
21
- return (
22
- <Drawer>
23
- <DrawerTrigger>Open</DrawerTrigger>
24
- <DrawerContent>
25
- <DrawerHeader>
26
- <DrawerTitle>Are you absolutely sure?</DrawerTitle>
27
- <DrawerDescription>This action cannot be undone.</DrawerDescription>
28
- </DrawerHeader>
29
- <DrawerFooter>
30
- <Button>Submit</Button>
31
- <DrawerClose>
32
- <Button variant="outline">Cancel</Button>
33
- </DrawerClose>
34
- </DrawerFooter>
35
- </DrawerContent>
36
- </Drawer>
37
- );
38
- },
39
- parameters: {
40
- layout: "centered",
41
- },
42
- tags: ["autodocs"],
43
- } satisfies Meta<typeof Drawer>;
44
-
45
- export default meta;
46
- type Story = StoryObj<typeof meta>;
47
-
48
- export const Default: Story = {
49
- args: {
50
- children: "Drawer",
51
- },
52
- };
53
-
54
- export const CustomDrawer: StoryObj<CustomDrawerProps> = {
55
- args: {
56
- children: "Drawer",
57
- open: true,
58
- },
59
- argTypes: {
60
- direction: {
61
- options: ["top", "right", "bottom", "left"],
62
- control: {
63
- type: "select",
64
- },
65
- },
66
- className: {
67
- control: {
68
- type: "text",
69
- },
70
- },
71
- open: {
72
- control: {
73
- type: "boolean",
74
- },
75
- },
76
- },
77
- render: (args) => {
78
- return <CustomDrawerComponent {...args} />;
79
- },
80
- };
@@ -1,2 +0,0 @@
1
- export * from "../../ui/drawer";
2
- export * from "./CustomDrawer";
@@ -1,42 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/nextjs";
2
- import { PageLayout } from "./index";
3
- import { Icon, Text } from "../../../components/dataDisplay";
4
- import { Button } from "../../../components/actions";
5
-
6
- const meta: Meta<typeof PageLayout> = {
7
- title: "Layout/PageLayout",
8
- component: PageLayout,
9
- parameters: {
10
- layout: "fullscreen",
11
- },
12
- tags: ["autodocs"],
13
- argTypes: {
14
- title: { control: "text" },
15
- subtitle: { control: "text" },
16
- header: { control: "text" },
17
- },
18
- };
19
-
20
- export default meta;
21
- type Story = StoryObj<typeof PageLayout>;
22
-
23
- export const Default: Story = {
24
- args: {
25
- title: "Page Title",
26
- subtitle: "Page Subtitle",
27
- children: <Text>Page content goes here.</Text>,
28
- },
29
- };
30
-
31
- export const WithHeader: Story = {
32
- args: {
33
- title: "Page Title",
34
- subtitle: "Page Subtitle",
35
- header: (
36
- <Button>
37
- <Icon name="MdAdd" />
38
- </Button>
39
- ),
40
- children: <Text>Page content goes here.</Text>,
41
- },
42
- };