@omniumretail/shared-resources 0.0.21 → 0.0.23

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 (29) hide show
  1. package/dist/bundle.js +1247 -437
  2. package/dist/types/hooks/index.d.ts +4 -0
  3. package/dist/types/hooks/useAnalyticsQuestionsQuery.hook.d.ts +9 -0
  4. package/dist/types/hooks/useAnalyticsSideBarQuery.hook.d.ts +7 -0
  5. package/dist/types/hooks/useContractStatesQuery.hook.d.ts +7 -0
  6. package/dist/types/hooks/useJobTitlesQuery.hook.d.ts +7 -0
  7. package/dist/types/hooks/useSingleUserIdMutateQuery.hook.d.ts +1 -1
  8. package/dist/types/interfaces/AnalyticsEvaluationCycle.d.ts +11 -0
  9. package/dist/types/interfaces/Answer.d.ts +2 -1
  10. package/dist/types/interfaces/ContractStates.d.ts +7 -0
  11. package/dist/types/interfaces/JobTitles.d.ts +7 -0
  12. package/dist/types/interfaces/ResponseList.d.ts +1 -1
  13. package/dist/types/interfaces/index.d.ts +2 -0
  14. package/dist/types/services/ApiService/index.d.ts +2 -2
  15. package/package.json +3 -3
  16. package/src/hooks/index.ts +4 -0
  17. package/src/hooks/useAnalyticsEvaluationCyclesQuery.hook.ts +1 -1
  18. package/src/hooks/useAnalyticsQuestionsQuery.hook.ts +22 -0
  19. package/src/hooks/useAnalyticsSideBarQuery.hook.ts +21 -0
  20. package/src/hooks/useContractStatesQuery.hook.ts +14 -0
  21. package/src/hooks/useJobTitlesQuery.hook.ts +14 -0
  22. package/src/hooks/useSingleUserIdMutateQuery.hook.ts +6 -5
  23. package/src/interfaces/AnalyticsEvaluationCycle.ts +14 -0
  24. package/src/interfaces/Answer.ts +2 -1
  25. package/src/interfaces/ContractStates.ts +7 -0
  26. package/src/interfaces/JobTitles.ts +7 -0
  27. package/src/interfaces/index.ts +2 -0
  28. package/src/services/ApiService/index.ts +43 -16
  29. package/tsconfig.json +2 -1
@@ -35,3 +35,7 @@ export * from './cancelEvaluationCycleQuery.hook';
35
35
  export * from './finishEvaluationCycleQuery.hook';
36
36
  export * from './cancelQuestionnaireQuery.hook';
37
37
  export * from './useTermNotificationQuery.hook';
38
+ export * from './useAnalyticsQuestionsQuery.hook';
39
+ export * from './useAnalyticsSideBarQuery.hook';
40
+ export * from './useJobTitlesQuery.hook';
41
+ export * from './useContractStatesQuery.hook';
@@ -0,0 +1,9 @@
1
+ import { UseQueryOptions } from "@tanstack/react-query";
2
+ import { Answer, ResponseList } from "../interfaces";
3
+ export interface AnalyticsQuestionsQuery extends UseQueryOptions<ResponseList<"Answers", Answer>> {
4
+ id: string;
5
+ page?: number;
6
+ records?: number;
7
+ tags?: string;
8
+ }
9
+ export declare const useAnalyticsQuestionsQueryHook: ({ page, records, id, tags }: AnalyticsQuestionsQuery) => import("@tanstack/react-query").UseQueryResult<ResponseList<"Answers", Answer>, unknown>;
@@ -0,0 +1,7 @@
1
+ import { UseQueryOptions } from "@tanstack/react-query";
2
+ import { AnalyticsEvaluationCycle } from "../interfaces";
3
+ export interface AnalyticsSideBar extends UseQueryOptions<AnalyticsEvaluationCycle[]> {
4
+ pSortDirection?: string;
5
+ pFilter?: string;
6
+ }
7
+ export declare const useAnalyticsSideBarQueryHook: ({ pSortDirection, pFilter }: AnalyticsSideBar) => import("@tanstack/react-query").UseQueryResult<AnalyticsEvaluationCycle[], unknown>;
@@ -0,0 +1,7 @@
1
+ import { UseQueryOptions } from "@tanstack/react-query";
2
+ import { ContractStates, ResponseList } from "../interfaces";
3
+ interface ContractStatesQueryProps extends UseQueryOptions<ContractStates> {
4
+ records: string;
5
+ }
6
+ export declare const useContractStatesQuery: ({ records }: ContractStatesQueryProps) => import("@tanstack/react-query").UseQueryResult<ResponseList<"ContractStates", ContractStates>, unknown>;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import { UseQueryOptions } from "@tanstack/react-query";
2
+ import { JobTitles, ResponseList } from "../interfaces";
3
+ interface JobTitlesQueryProps extends UseQueryOptions<JobTitles> {
4
+ records: string;
5
+ }
6
+ export declare const useJobTitlesQuery: ({ records }: JobTitlesQueryProps) => import("@tanstack/react-query").UseQueryResult<ResponseList<"JobTitles", JobTitles>, unknown>;
7
+ export {};
@@ -1,2 +1,2 @@
1
1
  import { SingleUser } from '../interfaces/User';
2
- export declare const useSingleUserIdMutateQuery: () => import("@tanstack/react-query").UseMutationResult<SingleUser, unknown, SingleUser, unknown>;
2
+ export declare const useSingleUserIdMutateQuery: (bodyType?: string) => import("@tanstack/react-query").UseMutationResult<SingleUser, unknown, SingleUser, unknown>;
@@ -5,4 +5,15 @@ export interface AnalyticsEvaluationCycle {
5
5
  export interface Items {
6
6
  Id: string;
7
7
  Name: string;
8
+ Categorys: CategoriesInterface[];
9
+ }
10
+ export interface CategoriesInterface {
11
+ CategoryId: string;
12
+ CategoryName: string;
13
+ SubCategory: CategoriesInterface[];
14
+ Questions: QuestionsInterface[];
15
+ }
16
+ export interface QuestionsInterface {
17
+ QuestionId: string;
18
+ QuestionName: string;
8
19
  }
@@ -1,4 +1,4 @@
1
- import { Categories } from './Questionnaire';
1
+ import { Categories, Questions } from './Questionnaire';
2
2
  export interface Answer {
3
3
  Id: string;
4
4
  EvaluationCycleId: string;
@@ -8,4 +8,5 @@ export interface Answer {
8
8
  StartDate: number;
9
9
  EndDate: number;
10
10
  CategoryAnswers: Categories[];
11
+ Question: Questions;
11
12
  }
@@ -0,0 +1,7 @@
1
+ export interface ContractStates {
2
+ Id: string;
3
+ Name: string;
4
+ Status: string;
5
+ CreateDate: number;
6
+ UpdatedDate: number;
7
+ }
@@ -0,0 +1,7 @@
1
+ export interface JobTitles {
2
+ Id: string;
3
+ Name: string;
4
+ Status: string;
5
+ CreateDate: number;
6
+ UpdatedDate: number;
7
+ }
@@ -1,4 +1,4 @@
1
- export type ResponseList<K extends string, T> = {
1
+ export declare type ResponseList<K extends string, T> = {
2
2
  [key in K]: T[];
3
3
  } & {
4
4
  Count: number;
@@ -17,3 +17,5 @@ export * from './Countries';
17
17
  export * from './Roles';
18
18
  export * from './AnswersUserSupervisor';
19
19
  export * from './TermNotification';
20
+ export * from './JobTitles';
21
+ export * from './ContractStates';
@@ -1,8 +1,8 @@
1
1
  import 'whatwg-fetch';
2
2
  export declare const get: <T>(path: string, params?: Record<string, unknown>) => Promise<T>;
3
3
  export declare const getAuth0: <T>(path: string, params?: Record<string, unknown>) => Promise<T>;
4
- export declare const putAuth0: <T>(path: string, params?: Record<string, unknown>, body?: unknown) => Promise<T>;
5
- export declare const postAuth0: <T>(path: string, params?: Record<string, unknown>, body?: unknown) => Promise<T>;
4
+ export declare const putAuth0: <T>(path: string, params?: Record<string, unknown>, body?: unknown, bodyType?: string) => Promise<T>;
5
+ export declare const postAuth0: <T>(path: string, params?: Record<string, unknown>, body?: unknown, bodyType?: string) => Promise<T>;
6
6
  export declare const toDeleteAuth0: <T>(path: string, params?: Record<string, unknown>, body?: unknown) => Promise<T>;
7
7
  export declare const post: <T>(path: string, body?: unknown) => Promise<T>;
8
8
  export declare const put: <T>(path: string, body?: unknown) => Promise<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/shared-resources",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "private": false,
5
5
  "description": "Shared Components and services or utils to the frontend versions",
6
6
  "main": "dist/bundle.js",
@@ -45,8 +45,8 @@
45
45
  "antd": "^4.23.4",
46
46
  "classnames": "^2.3.2",
47
47
  "date-fns": "^2.29.3",
48
- "react": "^18.2.0",
49
- "react-dom": "^18.2.0",
48
+ "react": "^18.0.0",
49
+ "react-dom": "^18.0.0",
50
50
  "react-router-dom": "^6.4.1",
51
51
  "use-query-params": "^2.1.1",
52
52
  "whatwg-fetch": "^3.6.2"
@@ -35,3 +35,7 @@ export * from './cancelEvaluationCycleQuery.hook';
35
35
  export * from './finishEvaluationCycleQuery.hook';
36
36
  export * from './cancelQuestionnaireQuery.hook';
37
37
  export * from './useTermNotificationQuery.hook';
38
+ export * from './useAnalyticsQuestionsQuery.hook';
39
+ export * from './useAnalyticsSideBarQuery.hook';
40
+ export * from './useJobTitlesQuery.hook';
41
+ export * from './useContractStatesQuery.hook';
@@ -1,5 +1,5 @@
1
1
  import { useQuery, UseQueryOptions } from "@tanstack/react-query";
2
- import { AnalyticsEvaluationCycle, ResponseList } from "../interfaces";
2
+ import { AnalyticsEvaluationCycle } from "../interfaces";
3
3
  import { getAuth0 } from "../services/ApiService";
4
4
 
5
5
  export interface AnalyticsEvaluationCycles extends UseQueryOptions<AnalyticsEvaluationCycle[]> {
@@ -0,0 +1,22 @@
1
+ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
2
+ import { Answer, ResponseList } from "../interfaces";
3
+ import { getAuth0 } from "../services/ApiService";
4
+
5
+ export interface AnalyticsQuestionsQuery extends UseQueryOptions<ResponseList<"Answers", Answer>> {
6
+ id: string;
7
+ page?: number;
8
+ records?: number;
9
+ tags?: string;
10
+ }
11
+
12
+ export const useAnalyticsQuestionsQueryHook = ({ page, records, id, tags }: AnalyticsQuestionsQuery) => {
13
+ return useQuery(
14
+ ['ANALYTICS_QUESTIONS_QUERY', page, records, id, tags],
15
+ () => getAuth0<ResponseList<"Answers", Answer>>(`/APE/Analytics/Questions`, {
16
+ pId: id,
17
+ pPage: page || 1,
18
+ pRecords: records || 50,
19
+ pTerms: tags,
20
+ }),
21
+ );
22
+ }
@@ -0,0 +1,21 @@
1
+ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
2
+ import { AnalyticsEvaluationCycle } from "../interfaces";
3
+ import { getAuth0 } from "../services/ApiService";
4
+
5
+ export interface AnalyticsSideBar extends UseQueryOptions<AnalyticsEvaluationCycle[]> {
6
+ pSortDirection?: string;
7
+ pFilter?: string;
8
+ }
9
+
10
+ export const useAnalyticsSideBarQueryHook = ({ pSortDirection, pFilter }: AnalyticsSideBar) => {
11
+ return useQuery(
12
+ ['ANALYTICS_SIDE_BAR_QUERY', pSortDirection, pFilter],
13
+ () => getAuth0<AnalyticsEvaluationCycle[]>(`/APE/Analytics/EvaluationCycles/SideBar`, {
14
+ pPage: 1,
15
+ pRecords: 50,
16
+ pSortBy: pFilter || 'Type',
17
+ pSortDirection: pSortDirection || 'asc',
18
+ pFilter: pFilter || 'Type'
19
+ }),
20
+ );
21
+ }
@@ -0,0 +1,14 @@
1
+ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
2
+ import { ContractStates, ResponseList } from "../interfaces";
3
+ import { getAuth0 } from "../services";
4
+
5
+ interface ContractStatesQueryProps extends UseQueryOptions<ContractStates> {
6
+ records: string;
7
+ }
8
+
9
+ export const useContractStatesQuery = ({ records }: ContractStatesQueryProps) => {
10
+ return useQuery(
11
+ ['CONTRACTSTATES_QUERY', records],
12
+ () => getAuth0<ResponseList<"ContractStates", ContractStates>>(`/ContractStates`, { pPage: 1, pRecords: records || 195 })
13
+ );
14
+ }
@@ -0,0 +1,14 @@
1
+ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
2
+ import { JobTitles, ResponseList } from "../interfaces";
3
+ import { getAuth0 } from "../services";
4
+
5
+ interface JobTitlesQueryProps extends UseQueryOptions<JobTitles> {
6
+ records: string;
7
+ }
8
+
9
+ export const useJobTitlesQuery = ({ records }: JobTitlesQueryProps) => {
10
+ return useQuery(
11
+ ['JOBTITLES_QUERY', records],
12
+ () => getAuth0<ResponseList<"JobTitles", JobTitles>>(`/JobTitles`, { pPage: 1, pRecords: records || 195 })
13
+ );
14
+ }
@@ -2,12 +2,13 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
2
2
  import { SingleUser } from '../interfaces/User';
3
3
  import { putAuth0, postAuth0 } from '../services/ApiService';
4
4
 
5
- export const useSingleUserIdMutateQuery = () => {
5
+ export const useSingleUserIdMutateQuery = (bodyType?: string) => {
6
6
  const queryClient = useQueryClient();
7
- return useMutation<SingleUser, unknown, SingleUser>((data: SingleUser) => {
8
- return data.UserId
9
- ? putAuth0(`/Users/${data.UserId}`, undefined, data)
10
- : postAuth0('/Users/', undefined, data);
7
+ return useMutation<SingleUser, unknown, SingleUser>((data: SingleUser | any) => {
8
+ const userId = bodyType === 'formdata' ? data.get('UserId') : data.UserId
9
+ return userId
10
+ ? putAuth0(`/Users/${userId}`, undefined, data, bodyType)
11
+ : postAuth0('/Users/', undefined, data, bodyType);
11
12
  }, {
12
13
  onSuccess: (data: SingleUser) => {
13
14
  queryClient.setQueryData(
@@ -7,4 +7,18 @@ export interface AnalyticsEvaluationCycle {
7
7
  export interface Items {
8
8
  Id: string;
9
9
  Name: string;
10
+ Categorys: CategoriesInterface[];
10
11
  }
12
+
13
+ export interface CategoriesInterface {
14
+ CategoryId: string;
15
+ CategoryName: string;
16
+ SubCategory: CategoriesInterface[];
17
+ Questions: QuestionsInterface[];
18
+ }
19
+
20
+ export interface QuestionsInterface {
21
+ QuestionId: string;
22
+ QuestionName: string;
23
+ }
24
+
@@ -1,4 +1,4 @@
1
- import { Categories } from './Questionnaire';
1
+ import { Categories, Questions } from './Questionnaire';
2
2
 
3
3
  export interface Answer {
4
4
  Id: string;
@@ -9,4 +9,5 @@ export interface Answer {
9
9
  StartDate: number;
10
10
  EndDate: number;
11
11
  CategoryAnswers: Categories[];
12
+ Question: Questions;
12
13
  }
@@ -0,0 +1,7 @@
1
+ export interface ContractStates {
2
+ Id: string;
3
+ Name: string;
4
+ Status: string;
5
+ CreateDate: number;
6
+ UpdatedDate: number;
7
+ }
@@ -0,0 +1,7 @@
1
+ export interface JobTitles {
2
+ Id: string;
3
+ Name: string;
4
+ Status: string;
5
+ CreateDate: number;
6
+ UpdatedDate: number;
7
+ }
@@ -17,3 +17,5 @@ export * from './Countries';
17
17
  export * from './Roles';
18
18
  export * from './AnswersUserSupervisor';
19
19
  export * from './TermNotification';
20
+ export * from './JobTitles';
21
+ export * from './ContractStates';
@@ -9,12 +9,12 @@ export const getAuth0 = <T>(path: string, params?: Record<string, unknown>): Pro
9
9
  return buildApiRequestForAuth0<T>(`${path}?${buildParams(params || {})}`, 'GET');
10
10
  }
11
11
 
12
- export const putAuth0 = <T>(path: string, params?: Record<string, unknown>, body?: unknown): Promise<T> => {
13
- return buildApiRequestForAuth0<T>(`${path}${buildParams(params || {})}`, 'PUT', body);
12
+ export const putAuth0 = <T>(path: string, params?: Record<string, unknown>, body?: unknown, bodyType?: string): Promise<T> => {
13
+ return buildApiRequestForAuth0<T>(`${path}${buildParams(params || {})}`, 'PUT', body, bodyType);
14
14
  }
15
15
 
16
- export const postAuth0 = <T>(path: string, params?: Record<string, unknown>, body?: unknown): Promise<T> => {
17
- return buildApiRequestForAuth0<T>(`${path}${buildParams(params || {})}`, 'POST', body);
16
+ export const postAuth0 = <T>(path: string, params?: Record<string, unknown>, body?: unknown,bodyType?: string): Promise<T> => {
17
+ return buildApiRequestForAuth0<T>(`${path}${buildParams(params || {})}`, 'POST', body, bodyType);
18
18
  }
19
19
 
20
20
  export const toDeleteAuth0 = <T>(path: string, params?: Record<string, unknown>, body?: unknown): Promise<T> => {
@@ -43,18 +43,32 @@ const buildParams = (params: Record<string, unknown>): string => {
43
43
  * @param path
44
44
  * @param method
45
45
  * @param data
46
+ * @param bodyType
46
47
  * @returns
47
48
  */
48
- const buildApiRequest = <T>(path: string, method = 'GET', data?: unknown): Promise<T> => {
49
+ const buildApiRequest = <T>(path: string, method = 'GET', data?: unknown, bodyType?: string): Promise<T> => {
49
50
  const requestUri = buildPath(path);
50
51
 
52
+ const headers: HeadersInit = {
53
+ Authorization: appConfig.token,
54
+ };
55
+
56
+ let body: FormData | string | undefined | any;
57
+
58
+ if (['POST', 'PUT'].includes(method)) {
59
+ if (bodyType === 'formdata') {
60
+ // Não é necessário dar set do contentType porque o fetch faz isso por nós quando usamos o fetch
61
+ body = data;
62
+ } else {
63
+ headers['Content-Type'] = 'application/json';
64
+ body = JSON.stringify(data);
65
+ }
66
+ }
67
+
51
68
  return fetch(requestUri, {
52
69
  method,
53
- headers: {
54
- 'Content-Type': 'application/json',
55
- Authorization: appConfig.token,
56
- } as HeadersInit,
57
- body: ['POST', 'PUT'].includes(method) ? JSON.stringify(data) : undefined,
70
+ headers,
71
+ body,
58
72
  }).then((response) => {
59
73
  if (response.status >= 200 && response.status <= 300) {
60
74
  return response.json();
@@ -70,16 +84,29 @@ const buildApiRequest = <T>(path: string, method = 'GET', data?: unknown): Promi
70
84
  * @param data
71
85
  * @returns
72
86
  */
73
- const buildApiRequestForAuth0 = <T>(path: string, method = 'GET', data?: unknown): Promise<T> => {
87
+ const buildApiRequestForAuth0 = <T>(path: string, method = 'GET', data?: unknown, bodyType?: string): Promise<T> => {
74
88
  const requestUri = buildPath(path);
75
89
 
90
+ const headers: HeadersInit = {
91
+ Authorization: `Bearer ${appConfig.tokenAuth0}`,
92
+ };
93
+
94
+ let body: FormData | string | undefined | any;
95
+
96
+ if (['POST', 'PUT'].includes(method)) {
97
+ if (bodyType === 'formdata') {
98
+ // Não é necessário dar set do contentType porque o fetch faz isso por nós quando usamos o fetch
99
+ body = data;
100
+ } else {
101
+ headers['Content-Type'] = 'application/json';
102
+ body = JSON.stringify(data);
103
+ }
104
+ }
105
+
76
106
  return fetch(requestUri, {
77
107
  method,
78
- headers: {
79
- 'Content-Type': 'application/json',
80
- Authorization: `Bearer ${appConfig.tokenAuth0}`,
81
- },
82
- body: ['POST', 'PUT'].includes(method) ? JSON.stringify(data) : undefined,
108
+ headers,
109
+ body,
83
110
  }).then((response) => {
84
111
  if (response.status >= 200 && response.status <= 300) {
85
112
  return response.json();
package/tsconfig.json CHANGED
@@ -20,7 +20,8 @@
20
20
  "noEmit": false,
21
21
  "sourceMap": true,
22
22
  "jsx": "react-jsx",
23
- "experimentalDecorators": true
23
+ "experimentalDecorators": true,
24
+ "downlevelIteration": true,
24
25
  },
25
26
  "include": ["src"]
26
27
  }