@voyantjs/crm-react 0.1.1

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 (74) hide show
  1. package/README.md +36 -0
  2. package/dist/client.d.ts +31 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +71 -0
  5. package/dist/hooks/index.d.ts +7 -0
  6. package/dist/hooks/index.d.ts.map +1 -0
  7. package/dist/hooks/index.js +6 -0
  8. package/dist/hooks/use-activities.d.ts +23 -0
  9. package/dist/hooks/use-activities.d.ts.map +1 -0
  10. package/dist/hooks/use-activities.js +38 -0
  11. package/dist/hooks/use-activity-mutation.d.ts +69 -0
  12. package/dist/hooks/use-activity-mutation.d.ts.map +1 -0
  13. package/dist/hooks/use-activity-mutation.js +60 -0
  14. package/dist/hooks/use-activity.d.ts +25 -0
  15. package/dist/hooks/use-activity.d.ts.map +1 -0
  16. package/dist/hooks/use-activity.js +34 -0
  17. package/dist/hooks/use-opportunities.d.ts +35 -0
  18. package/dist/hooks/use-opportunities.d.ts.map +1 -0
  19. package/dist/hooks/use-opportunities.js +41 -0
  20. package/dist/hooks/use-opportunity-mutation.d.ts +69 -0
  21. package/dist/hooks/use-opportunity-mutation.d.ts.map +1 -0
  22. package/dist/hooks/use-opportunity-mutation.js +41 -0
  23. package/dist/hooks/use-opportunity.d.ts +25 -0
  24. package/dist/hooks/use-opportunity.d.ts.map +1 -0
  25. package/dist/hooks/use-opportunity.js +20 -0
  26. package/dist/hooks/use-organization-mutation.d.ts +59 -0
  27. package/dist/hooks/use-organization-mutation.d.ts.map +1 -0
  28. package/dist/hooks/use-organization-mutation.js +41 -0
  29. package/dist/hooks/use-organization.d.ts +23 -0
  30. package/dist/hooks/use-organization.d.ts.map +1 -0
  31. package/dist/hooks/use-organization.js +20 -0
  32. package/dist/hooks/use-organizations.d.ts +29 -0
  33. package/dist/hooks/use-organizations.d.ts.map +1 -0
  34. package/dist/hooks/use-organizations.js +31 -0
  35. package/dist/hooks/use-people.d.ts +40 -0
  36. package/dist/hooks/use-people.d.ts.map +1 -0
  37. package/dist/hooks/use-people.js +41 -0
  38. package/dist/hooks/use-person-mutation.d.ts +82 -0
  39. package/dist/hooks/use-person-mutation.d.ts.map +1 -0
  40. package/dist/hooks/use-person-mutation.js +46 -0
  41. package/dist/hooks/use-person.d.ts +34 -0
  42. package/dist/hooks/use-person.d.ts.map +1 -0
  43. package/dist/hooks/use-person.js +28 -0
  44. package/dist/hooks/use-pipeline-mutation.d.ts +76 -0
  45. package/dist/hooks/use-pipeline-mutation.d.ts.map +1 -0
  46. package/dist/hooks/use-pipeline-mutation.js +76 -0
  47. package/dist/hooks/use-pipelines.d.ts +31 -0
  48. package/dist/hooks/use-pipelines.d.ts.map +1 -0
  49. package/dist/hooks/use-pipelines.js +42 -0
  50. package/dist/hooks/use-quote-mutation.d.ts +99 -0
  51. package/dist/hooks/use-quote-mutation.d.ts.map +1 -0
  52. package/dist/hooks/use-quote-mutation.js +70 -0
  53. package/dist/hooks/use-quote.d.ts +31 -0
  54. package/dist/hooks/use-quote.d.ts.map +1 -0
  55. package/dist/hooks/use-quote.js +37 -0
  56. package/dist/hooks/use-quotes.d.ts +24 -0
  57. package/dist/hooks/use-quotes.d.ts.map +1 -0
  58. package/dist/hooks/use-quotes.js +30 -0
  59. package/dist/hooks/use-stages.d.ts +37 -0
  60. package/dist/hooks/use-stages.d.ts.map +1 -0
  61. package/dist/hooks/use-stages.js +45 -0
  62. package/dist/index.d.ts +23 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +22 -0
  65. package/dist/provider.d.ts +39 -0
  66. package/dist/provider.d.ts.map +1 -0
  67. package/dist/provider.js +32 -0
  68. package/dist/query-keys.d.ts +85 -0
  69. package/dist/query-keys.d.ts.map +1 -0
  70. package/dist/query-keys.js +30 -0
  71. package/dist/schemas.d.ts +501 -0
  72. package/dist/schemas.d.ts.map +1 -0
  73. package/dist/schemas.js +179 -0
  74. package/package.json +75 -0
@@ -0,0 +1,20 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantContext } from "../provider.js";
5
+ import { crmQueryKeys } from "../query-keys.js";
6
+ import { opportunitySingleResponse } from "../schemas.js";
7
+ export function useOpportunity(id, options = {}) {
8
+ const { baseUrl, fetcher } = useVoyantContext();
9
+ const { enabled = true } = options;
10
+ return useQuery({
11
+ queryKey: crmQueryKeys.opportunity(id ?? ""),
12
+ queryFn: async () => {
13
+ if (!id)
14
+ throw new Error("useOpportunity requires an id");
15
+ const { data } = await fetchWithValidation(`/v1/crm/opportunities/${id}`, opportunitySingleResponse, { baseUrl, fetcher });
16
+ return data;
17
+ },
18
+ enabled: enabled && Boolean(id),
19
+ });
20
+ }
@@ -0,0 +1,59 @@
1
+ export interface CreateOrganizationInput {
2
+ name: string;
3
+ legalName?: string | null;
4
+ website?: string | null;
5
+ industry?: string | null;
6
+ relation?: string | null;
7
+ status?: string;
8
+ tags?: string[];
9
+ notes?: string | null;
10
+ [key: string]: unknown;
11
+ }
12
+ export type UpdateOrganizationInput = Partial<CreateOrganizationInput>;
13
+ export declare function useOrganizationMutation(): {
14
+ create: import("@tanstack/react-query").UseMutationResult<{
15
+ id: string;
16
+ name: string;
17
+ legalName: string | null;
18
+ website: string | null;
19
+ industry: string | null;
20
+ relation: string | null;
21
+ ownerId: string | null;
22
+ defaultCurrency: string | null;
23
+ preferredLanguage: string | null;
24
+ paymentTerms: number | null;
25
+ status: string;
26
+ source: string | null;
27
+ sourceRef: string | null;
28
+ tags: string[];
29
+ notes: string | null;
30
+ createdAt: string;
31
+ updatedAt: string;
32
+ }, Error, CreateOrganizationInput, unknown>;
33
+ update: import("@tanstack/react-query").UseMutationResult<{
34
+ id: string;
35
+ name: string;
36
+ legalName: string | null;
37
+ website: string | null;
38
+ industry: string | null;
39
+ relation: string | null;
40
+ ownerId: string | null;
41
+ defaultCurrency: string | null;
42
+ preferredLanguage: string | null;
43
+ paymentTerms: number | null;
44
+ status: string;
45
+ source: string | null;
46
+ sourceRef: string | null;
47
+ tags: string[];
48
+ notes: string | null;
49
+ createdAt: string;
50
+ updatedAt: string;
51
+ }, Error, {
52
+ id: string;
53
+ input: UpdateOrganizationInput;
54
+ }, unknown>;
55
+ remove: import("@tanstack/react-query").UseMutationResult<{
56
+ success: boolean;
57
+ }, Error, string, unknown>;
58
+ };
59
+ //# sourceMappingURL=use-organization-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-organization-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-organization-mutation.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAItE,wBAAgB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoBK,MAAM;eAAS,uBAAuB;;;;;EA+BjF"}
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { z } from "zod";
4
+ import { fetchWithValidation } from "../client.js";
5
+ import { useVoyantContext } from "../provider.js";
6
+ import { crmQueryKeys } from "../query-keys.js";
7
+ import { organizationSingleResponse } from "../schemas.js";
8
+ const deleteResponseSchema = z.object({ success: z.boolean() });
9
+ export function useOrganizationMutation() {
10
+ const { baseUrl, fetcher } = useVoyantContext();
11
+ const queryClient = useQueryClient();
12
+ const create = useMutation({
13
+ mutationFn: async (input) => {
14
+ const { data } = await fetchWithValidation("/v1/crm/organizations", organizationSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
15
+ return data;
16
+ },
17
+ onSuccess: () => {
18
+ void queryClient.invalidateQueries({ queryKey: crmQueryKeys.organizations() });
19
+ },
20
+ });
21
+ const update = useMutation({
22
+ mutationFn: async ({ id, input }) => {
23
+ const { data } = await fetchWithValidation(`/v1/crm/organizations/${id}`, organizationSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
24
+ return data;
25
+ },
26
+ onSuccess: (data) => {
27
+ void queryClient.invalidateQueries({ queryKey: crmQueryKeys.organizations() });
28
+ queryClient.setQueryData(crmQueryKeys.organization(data.id), data);
29
+ },
30
+ });
31
+ const remove = useMutation({
32
+ mutationFn: async (id) => {
33
+ return fetchWithValidation(`/v1/crm/organizations/${id}`, deleteResponseSchema, { baseUrl, fetcher }, { method: "DELETE" });
34
+ },
35
+ onSuccess: (_data, id) => {
36
+ void queryClient.invalidateQueries({ queryKey: crmQueryKeys.organizations() });
37
+ queryClient.removeQueries({ queryKey: crmQueryKeys.organization(id) });
38
+ },
39
+ });
40
+ return { create, update, remove };
41
+ }
@@ -0,0 +1,23 @@
1
+ export interface UseOrganizationOptions {
2
+ enabled?: boolean;
3
+ }
4
+ export declare function useOrganization(id: string | undefined, options?: UseOrganizationOptions): import("@tanstack/react-query").UseQueryResult<{
5
+ id: string;
6
+ name: string;
7
+ legalName: string | null;
8
+ website: string | null;
9
+ industry: string | null;
10
+ relation: string | null;
11
+ ownerId: string | null;
12
+ defaultCurrency: string | null;
13
+ preferredLanguage: string | null;
14
+ paymentTerms: number | null;
15
+ status: string;
16
+ source: string | null;
17
+ sourceRef: string | null;
18
+ tags: string[];
19
+ notes: string | null;
20
+ createdAt: string;
21
+ updatedAt: string;
22
+ }, Error>;
23
+ //# sourceMappingURL=use-organization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-organization.d.ts","sourceRoot":"","sources":["../../src/hooks/use-organization.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;UAiB3F"}
@@ -0,0 +1,20 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantContext } from "../provider.js";
5
+ import { crmQueryKeys } from "../query-keys.js";
6
+ import { organizationSingleResponse } from "../schemas.js";
7
+ export function useOrganization(id, options = {}) {
8
+ const { baseUrl, fetcher } = useVoyantContext();
9
+ const { enabled = true } = options;
10
+ return useQuery({
11
+ queryKey: crmQueryKeys.organization(id ?? ""),
12
+ queryFn: async () => {
13
+ if (!id)
14
+ throw new Error("useOrganization requires an id");
15
+ const { data } = await fetchWithValidation(`/v1/crm/organizations/${id}`, organizationSingleResponse, { baseUrl, fetcher });
16
+ return data;
17
+ },
18
+ enabled: enabled && Boolean(id),
19
+ });
20
+ }
@@ -0,0 +1,29 @@
1
+ import { type OrganizationsListFilters } from "../query-keys.js";
2
+ export interface UseOrganizationsOptions extends OrganizationsListFilters {
3
+ enabled?: boolean;
4
+ }
5
+ export declare function useOrganizations(options?: UseOrganizationsOptions): import("@tanstack/react-query").UseQueryResult<{
6
+ data: {
7
+ id: string;
8
+ name: string;
9
+ legalName: string | null;
10
+ website: string | null;
11
+ industry: string | null;
12
+ relation: string | null;
13
+ ownerId: string | null;
14
+ defaultCurrency: string | null;
15
+ preferredLanguage: string | null;
16
+ paymentTerms: number | null;
17
+ status: string;
18
+ source: string | null;
19
+ sourceRef: string | null;
20
+ tags: string[];
21
+ notes: string | null;
22
+ createdAt: string;
23
+ updatedAt: string;
24
+ }[];
25
+ total: number;
26
+ limit: number;
27
+ offset: number;
28
+ }, Error>;
29
+ //# sourceMappingURL=use-organizations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-organizations.d.ts","sourceRoot":"","sources":["../../src/hooks/use-organizations.ts"],"names":[],"mappings":"AAMA,OAAO,EAAgB,KAAK,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAG9E,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACvE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B;;;;;;;;;;;;;;;;;;;;;;;UAuBrE"}
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantContext } from "../provider.js";
5
+ import { crmQueryKeys } from "../query-keys.js";
6
+ import { organizationListResponse } from "../schemas.js";
7
+ export function useOrganizations(options = {}) {
8
+ const { baseUrl, fetcher } = useVoyantContext();
9
+ const { enabled = true, ...filters } = options;
10
+ return useQuery({
11
+ queryKey: crmQueryKeys.organizationsList(filters),
12
+ queryFn: () => {
13
+ const params = new URLSearchParams();
14
+ if (filters.search)
15
+ params.set("search", filters.search);
16
+ if (filters.ownerId)
17
+ params.set("ownerId", filters.ownerId);
18
+ if (filters.relation)
19
+ params.set("relation", filters.relation);
20
+ if (filters.status)
21
+ params.set("status", filters.status);
22
+ if (filters.limit !== undefined)
23
+ params.set("limit", String(filters.limit));
24
+ if (filters.offset !== undefined)
25
+ params.set("offset", String(filters.offset));
26
+ const qs = params.toString();
27
+ return fetchWithValidation(`/v1/crm/organizations${qs ? `?${qs}` : ""}`, organizationListResponse, { baseUrl, fetcher });
28
+ },
29
+ enabled,
30
+ });
31
+ }
@@ -0,0 +1,40 @@
1
+ import { type PeopleListFilters } from "../query-keys.js";
2
+ export interface UsePeopleOptions extends PeopleListFilters {
3
+ enabled?: boolean;
4
+ }
5
+ /**
6
+ * Lists people from the CRM with pagination + search + filters. Returns the
7
+ * raw `{ data, total, limit, offset }` envelope so consumers can build
8
+ * paginated tables directly from the response.
9
+ */
10
+ export declare function usePeople(options?: UsePeopleOptions): import("@tanstack/react-query").UseQueryResult<{
11
+ data: {
12
+ id: string;
13
+ organizationId: string | null;
14
+ firstName: string;
15
+ lastName: string;
16
+ jobTitle: string | null;
17
+ relation: string | null;
18
+ preferredLanguage: string | null;
19
+ preferredCurrency: string | null;
20
+ ownerId: string | null;
21
+ status: string;
22
+ source: string | null;
23
+ sourceRef: string | null;
24
+ tags: string[];
25
+ birthday: string | null;
26
+ notes: string | null;
27
+ createdAt: string;
28
+ updatedAt: string;
29
+ email: string | null;
30
+ phone: string | null;
31
+ website: string | null;
32
+ address: string | null;
33
+ city: string | null;
34
+ country: string | null;
35
+ }[];
36
+ total: number;
37
+ limit: number;
38
+ offset: number;
39
+ }, Error>;
40
+ //# sourceMappingURL=use-people.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-people.d.ts","sourceRoot":"","sources":["../../src/hooks/use-people.ts"],"names":[],"mappings":"AAMA,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGvE,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAuBvD"}
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantContext } from "../provider.js";
5
+ import { crmQueryKeys } from "../query-keys.js";
6
+ import { personListResponse } from "../schemas.js";
7
+ /**
8
+ * Lists people from the CRM with pagination + search + filters. Returns the
9
+ * raw `{ data, total, limit, offset }` envelope so consumers can build
10
+ * paginated tables directly from the response.
11
+ */
12
+ export function usePeople(options = {}) {
13
+ const { baseUrl, fetcher } = useVoyantContext();
14
+ const { enabled = true, ...filters } = options;
15
+ return useQuery({
16
+ queryKey: crmQueryKeys.peopleList(filters),
17
+ queryFn: () => {
18
+ const params = new URLSearchParams();
19
+ if (filters.search)
20
+ params.set("search", filters.search);
21
+ if (filters.organizationId)
22
+ params.set("organizationId", filters.organizationId);
23
+ if (filters.ownerId)
24
+ params.set("ownerId", filters.ownerId);
25
+ if (filters.relation)
26
+ params.set("relation", filters.relation);
27
+ if (filters.status)
28
+ params.set("status", filters.status);
29
+ if (filters.limit !== undefined)
30
+ params.set("limit", String(filters.limit));
31
+ if (filters.offset !== undefined)
32
+ params.set("offset", String(filters.offset));
33
+ const qs = params.toString();
34
+ return fetchWithValidation(`/v1/crm/people${qs ? `?${qs}` : ""}`, personListResponse, {
35
+ baseUrl,
36
+ fetcher,
37
+ });
38
+ },
39
+ enabled,
40
+ });
41
+ }
@@ -0,0 +1,82 @@
1
+ export interface CreatePersonInput {
2
+ firstName: string;
3
+ lastName: string;
4
+ organizationId?: string | null;
5
+ jobTitle?: string | null;
6
+ relation?: string | null;
7
+ status?: string;
8
+ email?: string | null;
9
+ phone?: string | null;
10
+ website?: string | null;
11
+ address?: string | null;
12
+ city?: string | null;
13
+ country?: string | null;
14
+ tags?: string[];
15
+ notes?: string | null;
16
+ [key: string]: unknown;
17
+ }
18
+ export type UpdatePersonInput = Partial<CreatePersonInput>;
19
+ /**
20
+ * Create, update, and delete mutations for people. All three share a single
21
+ * hook so the component can pick the action it needs. TanStack Query cache is
22
+ * invalidated on success.
23
+ */
24
+ export declare function usePersonMutation(): {
25
+ create: import("@tanstack/react-query").UseMutationResult<{
26
+ id: string;
27
+ organizationId: string | null;
28
+ firstName: string;
29
+ lastName: string;
30
+ jobTitle: string | null;
31
+ relation: string | null;
32
+ preferredLanguage: string | null;
33
+ preferredCurrency: string | null;
34
+ ownerId: string | null;
35
+ status: string;
36
+ source: string | null;
37
+ sourceRef: string | null;
38
+ tags: string[];
39
+ birthday: string | null;
40
+ notes: string | null;
41
+ createdAt: string;
42
+ updatedAt: string;
43
+ email: string | null;
44
+ phone: string | null;
45
+ website: string | null;
46
+ address: string | null;
47
+ city: string | null;
48
+ country: string | null;
49
+ }, Error, CreatePersonInput, unknown>;
50
+ update: import("@tanstack/react-query").UseMutationResult<{
51
+ id: string;
52
+ organizationId: string | null;
53
+ firstName: string;
54
+ lastName: string;
55
+ jobTitle: string | null;
56
+ relation: string | null;
57
+ preferredLanguage: string | null;
58
+ preferredCurrency: string | null;
59
+ ownerId: string | null;
60
+ status: string;
61
+ source: string | null;
62
+ sourceRef: string | null;
63
+ tags: string[];
64
+ birthday: string | null;
65
+ notes: string | null;
66
+ createdAt: string;
67
+ updatedAt: string;
68
+ email: string | null;
69
+ phone: string | null;
70
+ website: string | null;
71
+ address: string | null;
72
+ city: string | null;
73
+ country: string | null;
74
+ }, Error, {
75
+ id: string;
76
+ input: UpdatePersonInput;
77
+ }, unknown>;
78
+ remove: import("@tanstack/react-query").UseMutationResult<{
79
+ success: boolean;
80
+ }, Error, string, unknown>;
81
+ };
82
+ //# sourceMappingURL=use-person-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-person-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-person-mutation.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAI1D;;;;GAIG;AACH,wBAAgB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoBW,MAAM;eAAS,iBAAiB;;;;;EA+B3E"}
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { z } from "zod";
4
+ import { fetchWithValidation } from "../client.js";
5
+ import { useVoyantContext } from "../provider.js";
6
+ import { crmQueryKeys } from "../query-keys.js";
7
+ import { personSingleResponse } from "../schemas.js";
8
+ const deleteResponseSchema = z.object({ success: z.boolean() });
9
+ /**
10
+ * Create, update, and delete mutations for people. All three share a single
11
+ * hook so the component can pick the action it needs. TanStack Query cache is
12
+ * invalidated on success.
13
+ */
14
+ export function usePersonMutation() {
15
+ const { baseUrl, fetcher } = useVoyantContext();
16
+ const queryClient = useQueryClient();
17
+ const create = useMutation({
18
+ mutationFn: async (input) => {
19
+ const { data } = await fetchWithValidation("/v1/crm/people", personSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
20
+ return data;
21
+ },
22
+ onSuccess: () => {
23
+ void queryClient.invalidateQueries({ queryKey: crmQueryKeys.people() });
24
+ },
25
+ });
26
+ const update = useMutation({
27
+ mutationFn: async ({ id, input }) => {
28
+ const { data } = await fetchWithValidation(`/v1/crm/people/${id}`, personSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
29
+ return data;
30
+ },
31
+ onSuccess: (data) => {
32
+ void queryClient.invalidateQueries({ queryKey: crmQueryKeys.people() });
33
+ queryClient.setQueryData(crmQueryKeys.person(data.id), data);
34
+ },
35
+ });
36
+ const remove = useMutation({
37
+ mutationFn: async (id) => {
38
+ return fetchWithValidation(`/v1/crm/people/${id}`, deleteResponseSchema, { baseUrl, fetcher }, { method: "DELETE" });
39
+ },
40
+ onSuccess: (_data, id) => {
41
+ void queryClient.invalidateQueries({ queryKey: crmQueryKeys.people() });
42
+ queryClient.removeQueries({ queryKey: crmQueryKeys.person(id) });
43
+ },
44
+ });
45
+ return { create, update, remove };
46
+ }
@@ -0,0 +1,34 @@
1
+ export interface UsePersonOptions {
2
+ enabled?: boolean;
3
+ }
4
+ /**
5
+ * Fetches a single person by id. Returns `null` for unknown ids (the API
6
+ * responds with 404 which is treated as a thrown error — callers can wrap
7
+ * with a React Query `onError` or check `query.isError`).
8
+ */
9
+ export declare function usePerson(id: string | undefined, options?: UsePersonOptions): import("@tanstack/react-query").UseQueryResult<{
10
+ id: string;
11
+ organizationId: string | null;
12
+ firstName: string;
13
+ lastName: string;
14
+ jobTitle: string | null;
15
+ relation: string | null;
16
+ preferredLanguage: string | null;
17
+ preferredCurrency: string | null;
18
+ ownerId: string | null;
19
+ status: string;
20
+ source: string | null;
21
+ sourceRef: string | null;
22
+ tags: string[];
23
+ birthday: string | null;
24
+ notes: string | null;
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ email: string | null;
28
+ phone: string | null;
29
+ website: string | null;
30
+ address: string | null;
31
+ city: string | null;
32
+ country: string | null;
33
+ }, Error>;
34
+ //# sourceMappingURL=use-person.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-person.d.ts","sourceRoot":"","sources":["../../src/hooks/use-person.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,GAAE,gBAAqB;;;;;;;;;;;;;;;;;;;;;;;;UAgB/E"}
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantContext } from "../provider.js";
5
+ import { crmQueryKeys } from "../query-keys.js";
6
+ import { personSingleResponse } from "../schemas.js";
7
+ /**
8
+ * Fetches a single person by id. Returns `null` for unknown ids (the API
9
+ * responds with 404 which is treated as a thrown error — callers can wrap
10
+ * with a React Query `onError` or check `query.isError`).
11
+ */
12
+ export function usePerson(id, options = {}) {
13
+ const { baseUrl, fetcher } = useVoyantContext();
14
+ const { enabled = true } = options;
15
+ return useQuery({
16
+ queryKey: crmQueryKeys.person(id ?? ""),
17
+ queryFn: async () => {
18
+ if (!id)
19
+ throw new Error("usePerson requires an id");
20
+ const { data } = await fetchWithValidation(`/v1/crm/people/${id}`, personSingleResponse, {
21
+ baseUrl,
22
+ fetcher,
23
+ });
24
+ return data;
25
+ },
26
+ enabled: enabled && Boolean(id),
27
+ });
28
+ }
@@ -0,0 +1,76 @@
1
+ export interface CreatePipelineInput {
2
+ name: string;
3
+ entityType?: string;
4
+ isDefault?: boolean;
5
+ sortOrder?: number;
6
+ [key: string]: unknown;
7
+ }
8
+ export type UpdatePipelineInput = Partial<CreatePipelineInput>;
9
+ export interface CreateStageInput {
10
+ pipelineId: string;
11
+ name: string;
12
+ sortOrder?: number;
13
+ probability?: number | null;
14
+ isClosed?: boolean;
15
+ isWon?: boolean;
16
+ isLost?: boolean;
17
+ [key: string]: unknown;
18
+ }
19
+ export type UpdateStageInput = Partial<CreateStageInput>;
20
+ export declare function usePipelineMutation(): {
21
+ createPipeline: import("@tanstack/react-query").UseMutationResult<{
22
+ id: string;
23
+ entityType: string;
24
+ name: string;
25
+ isDefault: boolean;
26
+ sortOrder: number;
27
+ createdAt: string;
28
+ updatedAt: string;
29
+ }, Error, CreatePipelineInput, unknown>;
30
+ updatePipeline: import("@tanstack/react-query").UseMutationResult<{
31
+ id: string;
32
+ entityType: string;
33
+ name: string;
34
+ isDefault: boolean;
35
+ sortOrder: number;
36
+ createdAt: string;
37
+ updatedAt: string;
38
+ }, Error, {
39
+ id: string;
40
+ input: UpdatePipelineInput;
41
+ }, unknown>;
42
+ removePipeline: import("@tanstack/react-query").UseMutationResult<{
43
+ success: boolean;
44
+ }, Error, string, unknown>;
45
+ createStage: import("@tanstack/react-query").UseMutationResult<{
46
+ id: string;
47
+ pipelineId: string;
48
+ name: string;
49
+ sortOrder: number;
50
+ probability: number | null;
51
+ isClosed: boolean;
52
+ isWon: boolean;
53
+ isLost: boolean;
54
+ createdAt: string;
55
+ updatedAt: string;
56
+ }, Error, CreateStageInput, unknown>;
57
+ updateStage: import("@tanstack/react-query").UseMutationResult<{
58
+ id: string;
59
+ pipelineId: string;
60
+ name: string;
61
+ sortOrder: number;
62
+ probability: number | null;
63
+ isClosed: boolean;
64
+ isWon: boolean;
65
+ isLost: boolean;
66
+ createdAt: string;
67
+ updatedAt: string;
68
+ }, Error, {
69
+ id: string;
70
+ input: UpdateStageInput;
71
+ }, unknown>;
72
+ removeStage: import("@tanstack/react-query").UseMutationResult<{
73
+ success: boolean;
74
+ }, Error, string, unknown>;
75
+ };
76
+ //# sourceMappingURL=use-pipeline-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-pipeline-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-pipeline-mutation.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAE9D,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;AAIxD,wBAAgB,mBAAmB;;;;;;;;;;;;;;;;;;;YAoBS,MAAM;eAAS,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA8ClC,MAAM;eAAS,gBAAgB;;;;;EAsC1E"}