@greatapps/common 1.1.494 → 1.1.496

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 (49) hide show
  1. package/dist/components/navigation/ProjectSelectorPopover.mjs +0 -1
  2. package/dist/components/navigation/ProjectSelectorPopover.mjs.map +1 -1
  3. package/dist/components/navigation/subcomponents/ProjectSelector.mjs +10 -11
  4. package/dist/components/navigation/subcomponents/ProjectSelector.mjs.map +1 -1
  5. package/dist/index.mjs +22 -0
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/modules/projects/actions/create-project.action.mjs +10 -0
  8. package/dist/modules/projects/actions/create-project.action.mjs.map +1 -0
  9. package/dist/modules/projects/actions/delete-project.action.mjs +10 -0
  10. package/dist/modules/projects/actions/delete-project.action.mjs.map +1 -0
  11. package/dist/modules/projects/actions/list-projects.action.mjs +10 -0
  12. package/dist/modules/projects/actions/list-projects.action.mjs.map +1 -0
  13. package/dist/modules/projects/actions/update-project.action.mjs +10 -0
  14. package/dist/modules/projects/actions/update-project.action.mjs.map +1 -0
  15. package/dist/modules/projects/hooks/create-project.hook.mjs +40 -0
  16. package/dist/modules/projects/hooks/create-project.hook.mjs.map +1 -0
  17. package/dist/modules/projects/hooks/delete-project.hook.mjs +46 -0
  18. package/dist/modules/projects/hooks/delete-project.hook.mjs.map +1 -0
  19. package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +38 -0
  20. package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +1 -0
  21. package/dist/modules/projects/hooks/list-projects.hook.mjs +22 -0
  22. package/dist/modules/projects/hooks/list-projects.hook.mjs.map +1 -0
  23. package/dist/modules/projects/hooks/update-project.hook.mjs +20 -0
  24. package/dist/modules/projects/hooks/update-project.hook.mjs.map +1 -0
  25. package/dist/modules/projects/services/projects.service.mjs +83 -0
  26. package/dist/modules/projects/services/projects.service.mjs.map +1 -0
  27. package/dist/modules/projects/types.mjs +15 -0
  28. package/dist/modules/projects/types.mjs.map +1 -1
  29. package/dist/server.mjs +10 -0
  30. package/dist/server.mjs.map +1 -1
  31. package/package.json +1 -1
  32. package/src/components/navigation/ProjectSelectorPopover.tsx +5 -7
  33. package/src/components/navigation/subcomponents/ProjectSelector.tsx +14 -19
  34. package/src/index.ts +18 -1
  35. package/src/modules/projects/actions/create-project.action.ts +9 -0
  36. package/src/modules/projects/actions/delete-project.action.ts +8 -0
  37. package/src/modules/projects/actions/list-projects.action.ts +16 -0
  38. package/src/modules/projects/actions/update-project.action.ts +9 -0
  39. package/src/modules/projects/hooks/create-project.hook.ts +45 -0
  40. package/src/modules/projects/hooks/delete-project.hook.ts +49 -0
  41. package/src/modules/projects/hooks/list-infinite-projects.hook.ts +42 -0
  42. package/src/modules/projects/hooks/list-projects.hook.ts +23 -0
  43. package/src/modules/projects/hooks/update-project.hook.ts +21 -0
  44. package/src/modules/projects/services/projects.service.ts +123 -0
  45. package/src/modules/projects/types.ts +46 -0
  46. package/src/server.ts +7 -0
  47. package/dist/components/navigation/types.mjs +0 -1
  48. package/dist/components/navigation/types.mjs.map +0 -1
  49. package/src/components/navigation/types.ts +0 -6
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+
3
+ import { useQuery, keepPreviousData } from '@tanstack/react-query';
4
+ import { listProjectsAction } from '../actions/list-projects.action';
5
+ import type { ListProjectsActionParams } from '../actions/list-projects.action';
6
+ import { withAction } from '../../../utils/withAction';
7
+ import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
8
+
9
+ export const PROJECTS_BASE_KEY = ['projects'] as const;
10
+
11
+ export const PROJECTS_QUERY_KEY = (params?: ListProjectsActionParams) =>
12
+ [...PROJECTS_BASE_KEY, params] as const;
13
+
14
+ export function useProjects(params?: ListProjectsActionParams) {
15
+ const queryKey = useAuthQueryKey([...PROJECTS_QUERY_KEY(params)]);
16
+
17
+ return useQuery({
18
+ queryKey,
19
+ queryFn: withAction(() => listProjectsAction(params)),
20
+ staleTime: 30_000,
21
+ placeholderData: keepPreviousData,
22
+ });
23
+ }
@@ -0,0 +1,21 @@
1
+ 'use client';
2
+
3
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
4
+ import { updateProjectAction } from '../actions/update-project.action';
5
+ import { withAction } from '../../../utils/withAction';
6
+ import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
7
+ import { PROJECTS_BASE_KEY } from './list-projects.hook';
8
+ import type { UpdateProjectRequest } from '../types';
9
+
10
+ export function useUpdateProject() {
11
+ const queryClient = useQueryClient();
12
+ const projectsKey = useAuthQueryKey([...PROJECTS_BASE_KEY]);
13
+
14
+ return useMutation({
15
+ mutationFn: ({ projectId, data }: { projectId: number; data: UpdateProjectRequest }) =>
16
+ withAction(updateProjectAction)(projectId, data),
17
+ onSuccess: () => {
18
+ queryClient.invalidateQueries({ queryKey: projectsKey });
19
+ },
20
+ });
21
+ }
@@ -0,0 +1,123 @@
1
+ import 'server-only';
2
+
3
+ import { api } from '../../../infra/api/client';
4
+ import { ApiError } from '../../../infra/api/types';
5
+ import { buildQueryParams } from '../../../infra/utils/params';
6
+ import { getUserContext } from '../../auth/utils/get-user-context';
7
+ import { assertManagementSubscription } from '../../auth/utils/assert-management-subscription';
8
+ import {
9
+ Project,
10
+ ProjectSchema,
11
+ ProjectsPage,
12
+ CreateProjectRequest,
13
+ UpdateProjectRequest,
14
+ } from '../types';
15
+
16
+ interface ApiListResponse<T> {
17
+ data: T[];
18
+ total: number;
19
+ status: number;
20
+ message?: string;
21
+ }
22
+
23
+ interface ApiMutationResponse {
24
+ status: number;
25
+ message?: string;
26
+ data?: Project[];
27
+ }
28
+
29
+ interface ListProjectsParams {
30
+ page?: number;
31
+ limit?: number;
32
+ sort?: string;
33
+ search?: string;
34
+ deleted?: number;
35
+ }
36
+
37
+ class ProjectsService {
38
+ async list(params: ListProjectsParams = {}): Promise<ProjectsPage> {
39
+ const { id_account, id_user } = await getUserContext();
40
+ const query = buildQueryParams(params as Record<string, string | number | boolean | undefined>);
41
+ const url = `/account/${id_account}/user/${id_user}/projects${query ? `?${query}` : ''}`;
42
+
43
+ const response = await api.apps.get<ApiListResponse<Project>>(url);
44
+
45
+ if (response.status === 0) {
46
+ throw new ApiError(
47
+ response.message || 'Erro ao listar projetos',
48
+ 'LIST_PROJECTS_FAILED',
49
+ 400
50
+ );
51
+ }
52
+
53
+ return {
54
+ data: (response.data || []).map((item) => ProjectSchema.parse(item)),
55
+ total: response.total || 0,
56
+ page: params.page ?? 1,
57
+ };
58
+ }
59
+
60
+ async create(data: CreateProjectRequest): Promise<Project> {
61
+ await assertManagementSubscription();
62
+ const { id_account, id_user } = await getUserContext();
63
+ const url = `/account/${id_account}/user/${id_user}/projects`;
64
+
65
+ const response = await api.apps.post<ApiMutationResponse>(url, data);
66
+
67
+ if (response.status === 0) {
68
+ throw new ApiError(
69
+ response.message || 'Erro ao criar projeto',
70
+ 'CREATE_PROJECT_FAILED',
71
+ 400
72
+ );
73
+ }
74
+
75
+ if (!response.data || response.data.length === 0) {
76
+ throw new ApiError('Resposta inválida ao criar projeto', 'INVALID_RESPONSE', 500);
77
+ }
78
+
79
+ return ProjectSchema.parse(response.data[0]);
80
+ }
81
+
82
+ async update(projectId: number, data: UpdateProjectRequest): Promise<Project> {
83
+ await assertManagementSubscription();
84
+ const { id_account, id_user } = await getUserContext();
85
+ const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;
86
+
87
+ const response = await api.apps.put<ApiMutationResponse>(url, data);
88
+
89
+ if (response.status === 0) {
90
+ throw new ApiError(
91
+ response.message || 'Erro ao atualizar projeto',
92
+ 'UPDATE_PROJECT_FAILED',
93
+ 400
94
+ );
95
+ }
96
+
97
+ if (!response.data || response.data.length === 0) {
98
+ throw new ApiError('Resposta inválida ao atualizar projeto', 'INVALID_RESPONSE', 500);
99
+ }
100
+
101
+ return ProjectSchema.parse(response.data[0]);
102
+ }
103
+
104
+ async delete(projectId: number, moveToProjectId: number): Promise<void> {
105
+ await assertManagementSubscription();
106
+ const { id_account, id_user } = await getUserContext();
107
+ const url = `/account/${id_account}/user/${id_user}/projects/${projectId}`;
108
+
109
+ const response = await api.apps.delete<ApiMutationResponse>(url, {
110
+ body: JSON.stringify({ id_project_to_move: moveToProjectId }),
111
+ });
112
+
113
+ if (response.status === 0) {
114
+ throw new ApiError(
115
+ response.message || 'Erro ao deletar projeto',
116
+ 'DELETE_PROJECT_FAILED',
117
+ 400
118
+ );
119
+ }
120
+ }
121
+ }
122
+
123
+ export const projectsService = new ProjectsService();
@@ -1,5 +1,51 @@
1
1
  import { z } from "zod";
2
2
 
3
+ // ============================================================================
4
+ // Project
5
+ // ============================================================================
6
+
7
+ export const ProjectSchema = z.object({
8
+ id: z.union([z.number(), z.string()]).transform(Number),
9
+ id_wl: z.union([z.number(), z.string()]).transform(Number),
10
+ id_account: z.union([z.number(), z.string()]).transform(Number),
11
+ title: z.string(),
12
+ photo: z.string().nullable().optional(),
13
+ id_api: z.union([z.number(), z.string()]).nullable().optional(),
14
+ id_form_integration: z.union([z.number(), z.string()]).nullable().optional(),
15
+ total_users: z.string().optional(),
16
+ deleted: z
17
+ .union([z.boolean(), z.number()])
18
+ .transform((v) => Boolean(v))
19
+ .default(false),
20
+ datetime_add: z.string().nullable().optional(),
21
+ datetime_alt: z.string().nullable().optional(),
22
+ datetime_del: z.string().nullable().optional(),
23
+ });
24
+
25
+ export type Project = z.infer<typeof ProjectSchema>;
26
+
27
+ export interface ProjectsPage {
28
+ data: Project[];
29
+ total: number;
30
+ page: number;
31
+ }
32
+
33
+ export interface CreateProjectRequest {
34
+ title: string;
35
+ photo?: string;
36
+ id_api?: number;
37
+ users?: number[];
38
+ }
39
+
40
+ export interface UpdateProjectRequest {
41
+ title: string;
42
+ photo?: string;
43
+ }
44
+
45
+ // ============================================================================
46
+ // Project Users
47
+ // ============================================================================
48
+
3
49
  export const ProjectUserSchema = z.object({
4
50
  id_user: z.union([z.number(), z.string()]).transform(Number),
5
51
  id_account: z.union([z.number(), z.string()]).transform(Number),
package/src/server.ts CHANGED
@@ -32,6 +32,13 @@ export { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-p
32
32
  export { hasSubscriptionExpired } from './modules/subscriptions/utils/has-subscription-expired';
33
33
  export { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';
34
34
 
35
+ // Project Services & Actions (server-only)
36
+ export { projectsService } from './modules/projects/services/projects.service';
37
+ export { listProjectsAction } from './modules/projects/actions/list-projects.action';
38
+ export { createProjectAction } from './modules/projects/actions/create-project.action';
39
+ export { updateProjectAction } from './modules/projects/actions/update-project.action';
40
+ export { deleteProjectAction } from './modules/projects/actions/delete-project.action';
41
+
35
42
  // Project Users Services & Actions (server-only)
36
43
  export { projectUsersService } from './modules/projects/services/project-users.service';
37
44
  export { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,6 +0,0 @@
1
- export interface NavigationProject {
2
- id: number;
3
- title: string;
4
- photo?: string | null;
5
- total_users?: string;
6
- }