Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.1.10",
"antd": "^4.16.6",
"axios": "^0.21.1",
"axios": "^0.21.4",
"axios-mock-adapter": "^1.20.0",
"classnames": "^2.3.1",
"craco-antd": "^1.19.0",
"i18next": "^20.3.2",
Expand Down
24 changes: 23 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import axios, { AxiosRequestConfig } from "axios";
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
import moment from "moment";

import { ENV } from "@app/constants/env";
import { AuthEndpointsEnum, getTokens } from "@app/features/auth/auth";
import { toCamel, toSnakeCase } from "@app/helpers/object-convert.helper";

/**
* All the endpoint that do not require an access token
Expand All @@ -26,6 +27,9 @@ export const getRefreshedToken = () => {
* @param {AxiosRequestConfig} request
*/
const authInterceptor = async (request: AxiosRequestConfig) => {
request.params = toSnakeCase(request.params, true);
request.data = toSnakeCase(request.data, true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets leave this to the project, this totally depends on the backend implementation and debugging to find this can be difficult

const isAnonymous = anonymousEndpoints.some(endpoint =>
request.url?.startsWith(endpoint)
);
Expand All @@ -46,10 +50,28 @@ const authInterceptor = async (request: AxiosRequestConfig) => {
return request;
};

/**
* Axios response interceptors
* @param {AxiosResponse} response
*/
const responseInterceptor = (response: AxiosResponse) => {
response.data = toCamel(response.data);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, it can vary from projects

return response;
};

/**
* Axios error interceptor
* @param {AxiosError} axiosError
*/
const errorInterceptor = (axiosError: AxiosError) => {
return axiosError;
};

/** Setup an API instance */
export const api = axios.create({
baseURL: ENV.API_HOST,
headers: { "Content-Type": "application/json" },
});

api.interceptors.request.use(authInterceptor);
api.interceptors.response.use(responseInterceptor, errorInterceptor);
7 changes: 7 additions & 0 deletions src/api/mock-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import MockAdapter from "axios-mock-adapter";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, lets have it in the readme, instead of adding a package that we might not use.


import { api } from "./api";

export const mockApi = new MockAdapter(api, {
onNoMatch: "passthrough",
});
15 changes: 15 additions & 0 deletions src/dummy-data/client-by-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move it to clients folder, so its easy to cleanup

"data": {
"id": 1,
"name": "Tobye Dealtry",
"address": "321 Milwaukee Point",
"office_hours_from": "17:06:54",
"office_hours_to": "9:17:06",
"phone": "790-843-3927",
"web": "LTL",
"photo": "https://robohash.org/laborumsitmagni.png?size=50x50&set=set1",
"created_at": "2020-12-25T11:02:52Z",
"updated_at": "2021-03-09T00:28:41Z",
"deleted_at": ""
}
}
270 changes: 270 additions & 0 deletions src/dummy-data/clients.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
{
"data": [
{
"id": 1,
"name": "Tobye Dealtry",
"address": "321 Milwaukee Point",
"office_hours_from": "17:06:54",
"office_hours_to": "9:17:06",
"phone": "790-843-3927",
"web": "LTL",
"photo": "https://robohash.org/laborumsitmagni.png?size=50x50&set=set1",
"created_at": "2020-12-25T11:02:52Z",
"updated_at": "2021-03-09T00:28:41Z",
"deleted_at": ""
},
{
"id": 2,
"name": "Audy Gadeaux",
"address": "5052 Coolidge Crossing",
"office_hours_from": "15:44:18",
"office_hours_to": "4:54:38",
"phone": "480-850-7774",
"web": "QCAT",
"photo": "https://robohash.org/rerumaliquidreiciendis.png?size=50x50&set=set1",
"created_at": "2021-01-27T02:25:45Z",
"updated_at": "2020-11-17T03:52:13Z",
"deleted_at": ""
},
{
"id": 3,
"name": "Sonny Scudder",
"address": "66 Crescent Oaks Alley",
"office_hours_from": "12:06:46",
"office_hours_to": "18:39:29",
"phone": "995-120-9052",
"web": "Corporate Events",
"photo": "https://robohash.org/quamabnobis.png?size=50x50&set=set1",
"created_at": "2021-01-18T15:58:56Z",
"updated_at": "2021-04-16T20:13:31Z",
"deleted_at": ""
},
{
"id": 4,
"name": "Katherine Cristoferi",
"address": "263 Main Terrace",
"office_hours_from": "11:45:18",
"office_hours_to": "14:33:26",
"phone": "322-845-7746",
"web": "Business Planning",
"photo": "https://robohash.org/facererepudiandaevel.png?size=50x50&set=set1",
"created_at": "2021-06-26T14:13:36Z",
"updated_at": "2020-11-05T23:45:20Z",
"deleted_at": ""
},
{
"id": 5,
"name": "Davida Haukey",
"address": "3 Pawling Drive",
"office_hours_from": "14:26:51",
"office_hours_to": "4:32:17",
"phone": "263-813-2382",
"web": "RHCE",
"photo": "https://robohash.org/pariaturfacilisofficiis.png?size=50x50&set=set1",
"created_at": "2021-04-29T19:58:43Z",
"updated_at": "2021-04-28T14:58:19Z",
"deleted_at": ""
},
{
"id": 6,
"name": "Jesus Rustman",
"address": "8036 Ridgeview Terrace",
"office_hours_from": "20:48:46",
"office_hours_to": "0:51:58",
"phone": "676-826-4027",
"web": "Pediatrics",
"photo": "https://robohash.org/modivoluptasexcepturi.png?size=50x50&set=set1",
"created_at": "2021-01-16T22:18:24Z",
"updated_at": "2020-09-20T09:59:46Z",
"deleted_at": ""
},
{
"id": 7,
"name": "Onofredo Eggleston",
"address": "3004 Huxley Center",
"office_hours_from": "9:15:45",
"office_hours_to": "10:11:46",
"phone": "916-342-2719",
"web": "SSL Certificates",
"photo": "https://robohash.org/etarchitectonecessitatibus.png?size=50x50&set=set1",
"created_at": "2020-12-04T14:36:16Z",
"updated_at": "2021-05-03T10:04:35Z",
"deleted_at": ""
},
{
"id": 8,
"name": "Archibaldo Bunn",
"address": "21230 Anzinger Crossing",
"office_hours_from": "23:22:34",
"office_hours_to": "4:20:27",
"phone": "405-496-5793",
"web": "Hygiene",
"photo": "https://robohash.org/voluptatemestquam.png?size=50x50&set=set1",
"created_at": "2021-04-16T03:51:06Z",
"updated_at": "2020-10-07T16:16:43Z",
"deleted_at": ""
},
{
"id": 9,
"name": "Neill Bollins",
"address": "6140 Hallows Parkway",
"office_hours_from": "0:45:33",
"office_hours_to": "23:02:20",
"phone": "477-938-5895",
"web": "Design Patterns",
"photo": "https://robohash.org/amagnamnumquam.png?size=50x50&set=set1",
"created_at": "2020-11-04T18:36:03Z",
"updated_at": "2021-03-20T04:22:45Z",
"deleted_at": ""
},
{
"id": 10,
"name": "Kaila Lampbrecht",
"address": "5 Hermina Junction",
"office_hours_from": "6:43:30",
"office_hours_to": "11:10:46",
"phone": "480-963-2992",
"web": "VLDB",
"photo": "https://robohash.org/idinerror.png?size=50x50&set=set1",
"created_at": "2021-06-11T06:06:11Z",
"updated_at": "2021-07-11T13:22:32Z",
"deleted_at": ""
},
{
"id": 11,
"name": "Candie Juschka",
"address": "3 Debs Terrace",
"office_hours_from": "13:07:23",
"office_hours_to": "10:41:24",
"phone": "268-920-8149",
"web": "KML",
"photo": "https://robohash.org/similiquelaboresoluta.png?size=50x50&set=set1",
"created_at": "2021-04-07T12:50:30Z",
"updated_at": "2021-06-19T07:52:13Z",
"deleted_at": ""
},
{
"id": 12,
"name": "Shelli Sabey",
"address": "72463 Carpenter Drive",
"office_hours_from": "8:52:25",
"office_hours_to": "8:36:21",
"phone": "782-492-0204",
"web": "Program Management",
"photo": "https://robohash.org/laboriosamvoluptasvoluptate.png?size=50x50&set=set1",
"created_at": "2021-06-07T08:46:41Z",
"updated_at": "2021-03-07T11:18:21Z",
"deleted_at": ""
},
{
"id": 13,
"name": "Stella Scaplehorn",
"address": "78 Eastlawn Street",
"office_hours_from": "3:23:08",
"office_hours_to": "7:30:12",
"phone": "815-476-0456",
"web": "MSP Practitioner",
"photo": "https://robohash.org/nametquod.png?size=50x50&set=set1",
"created_at": "2021-03-18T01:11:44Z",
"updated_at": "2021-06-29T09:06:48Z",
"deleted_at": ""
},
{
"id": 14,
"name": "Kevan Wines",
"address": "25773 Arkansas Hill",
"office_hours_from": "10:14:52",
"office_hours_to": "23:38:08",
"phone": "304-861-1637",
"web": "Mergers & Acquisitions",
"photo": "https://robohash.org/praesentiuminciduntalias.png?size=50x50&set=set1",
"created_at": "2021-04-22T01:28:47Z",
"updated_at": "2021-08-05T14:03:35Z",
"deleted_at": ""
},
{
"id": 15,
"name": "Rosmunda Coxall",
"address": "34 West Drive",
"office_hours_from": "20:23:20",
"office_hours_to": "1:33:49",
"phone": "685-895-9004",
"web": "LMS Test.Lab",
"photo": "https://robohash.org/delenitifacilisearum.png?size=50x50&set=set1",
"created_at": "2020-12-07T07:59:01Z",
"updated_at": "2020-10-25T17:29:02Z",
"deleted_at": ""
},
{
"id": 16,
"name": "Vite Willock",
"address": "10 Pearson Circle",
"office_hours_from": "15:28:34",
"office_hours_to": "2:18:10",
"phone": "428-749-4461",
"web": "Workplace Safety",
"photo": "https://robohash.org/doloresrepudiandaecorrupti.png?size=50x50&set=set1",
"created_at": "2021-02-10T03:26:33Z",
"updated_at": "2020-09-27T23:48:06Z",
"deleted_at": ""
},
{
"id": 17,
"name": "Pascale Tassell",
"address": "2 Springview Alley",
"office_hours_from": "1:03:47",
"office_hours_to": "14:55:59",
"phone": "265-973-8656",
"web": "Ultrasonic Welding",
"photo": "https://robohash.org/idiustorerum.png?size=50x50&set=set1",
"created_at": "2021-08-14T04:50:15Z",
"updated_at": "2021-01-26T11:04:34Z",
"deleted_at": ""
},
{
"id": 18,
"name": "Niall McArd",
"address": "4 Stang Way",
"office_hours_from": "13:15:48",
"office_hours_to": "7:22:27",
"phone": "428-779-3952",
"web": "DXX",
"photo": "https://robohash.org/dictaetpossimus.png?size=50x50&set=set1",
"created_at": "2021-09-11T04:44:14Z",
"updated_at": "2021-05-07T23:00:54Z",
"deleted_at": ""
},
{
"id": 19,
"name": "Putnam Shortland",
"address": "4 1st Park",
"office_hours_from": "8:51:06",
"office_hours_to": "21:17:37",
"phone": "966-407-9689",
"web": "EEG",
"photo": "https://robohash.org/autofficiaquia.png?size=50x50&set=set1",
"created_at": "2021-06-18T20:21:34Z",
"updated_at": "2021-05-14T06:50:54Z",
"deleted_at": ""
},
{
"id": 20,
"name": "Myra Baudino",
"address": "09549 Katie Junction",
"office_hours_from": "6:25:27",
"office_hours_to": "2:13:31",
"phone": "115-531-6836",
"web": "Digital Signage",
"photo": "https://robohash.org/harumducimustempora.png?size=50x50&set=set1",
"created_at": "2021-01-20T20:20:16Z",
"updated_at": "2021-06-30T08:59:50Z",
"deleted_at": ""
}
],
"pagination": {
"page": 1,
"per_page": 20,
"total": 50,
"total_pages": 3
}
}
2 changes: 1 addition & 1 deletion src/features/auth/redux/auth.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const authSlice = createSlice({
getMe.fulfilled,
(state, action: PayloadAction<UserResponseDef>) => {
const { data } = action.payload;
const name = `${data.first_name} ${data.last_name}`;
const name = `${data.firstName} ${data.lastName}`;

const user: UserDef = {
...data,
Expand Down
5 changes: 2 additions & 3 deletions src/features/auth/types/auth.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ export interface InitialStateDef {
loading: boolean;
}

/* eslint-disable camelcase */
export type UserResponseDef = {
data: {
id: number;
first_name: string;
last_name: string;
firstName: string;
lastName: string;
avatar: string;
email: string;
};
Expand Down
Loading