Skip to content

Commit ee40342

Browse files
committed
open april, add map, toast to schedule, prettier
1 parent da60135 commit ee40342

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4155
-2944
lines changed

src/api/index.js

+90-87
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import axios from 'axios';
2-
import { toast } from "react-hot-toast";
2+
import { toast } from 'react-hot-toast';
33

4-
const currentURL = window.location.protocol + "//" + window.location.hostname + "/api/";
4+
const currentURL =
5+
window.location.protocol + '//' + window.location.hostname + '/api/';
56

67
axios.defaults.baseURL = currentURL;
78

@@ -13,19 +14,19 @@ const clearAuthHeader = () => {
1314
axios.defaults.headers.common.Authorization = '';
1415
};
1516

16-
export const logIn = async (credentials) => {
17-
try {
18-
const resp = await axios.post('/admin/login', credentials);
19-
setAuthHeader(resp.data);
20-
localStorage.setItem('token', resp.data);
21-
} catch (error) {
22-
toast.error("The email address or password is incorrect. Please retry", {
23-
duration: 3000,
24-
});
25-
}
26-
};
17+
export const logIn = async credentials => {
18+
try {
19+
const resp = await axios.post('/admin/login', credentials);
20+
setAuthHeader(resp.data);
21+
localStorage.setItem('token', resp.data);
22+
} catch (error) {
23+
toast.error('The email address or password is incorrect. Please retry', {
24+
duration: 3000,
25+
});
26+
}
27+
};
2728

28-
export const logOut = async () => {
29+
export const logOut = async () => {
2930
try {
3031
await axios.post('/admin/logout');
3132
clearAuthHeader();
@@ -43,10 +44,10 @@ export const refreshAdmin = async () => {
4344
const response = await axios.get('/admin/check');
4445
return response;
4546
} catch (error) {
46-
if(error.response && error.response.status === 401) {
47+
if (error.response && error.response.status === 401) {
4748
localStorage.clear();
4849
} else {
49-
toast.error("Something went wrong. Please retry", {
50+
toast.error('Something went wrong. Please retry', {
5051
duration: 3000,
5152
});
5253
}
@@ -55,69 +56,66 @@ export const refreshAdmin = async () => {
5556
};
5657

5758
export const getAppointments = async () => {
58-
try {
59-
const resp = await axios.get('/appointments');
60-
return resp.data;
59+
try {
60+
const resp = await axios.get('/appointments');
61+
return resp.data;
62+
} catch (error) {
63+
toast.error('Oops! Something went wrong. Please retry later', {
64+
duration: 3000,
65+
});
66+
}
67+
};
6168

62-
} catch (error) {
63-
toast.error("Oops! Something went wrong. Please retry later", {
64-
duration: 3000,
65-
});
69+
export const getAppointmentsByDate = async date => {
70+
try {
71+
if (!axios.defaults.headers.common.Authorization) {
72+
return;
6673
}
67-
};
68-
69-
export const getAppointmentsByDate = async (date) => {
70-
try {
71-
if(!axios.defaults.headers.common.Authorization) {
72-
return;
73-
}
74-
const resp = await axios.get(`/appointments?date=${date}`);
75-
return resp.data;
76-
77-
} catch (error) {
78-
toast.error("Oops! Something went wrong. Please retry later", {
79-
duration: 3000,
80-
});
74+
const resp = await axios.get(`/appointments?date=${date}`);
75+
return resp.data;
76+
} catch (error) {
77+
toast.error('Oops! Something went wrong. Please retry later', {
78+
duration: 3000,
79+
});
80+
}
81+
};
82+
83+
export const getAppointmentsByMonth = async month => {
84+
try {
85+
if (!axios.defaults.headers.common.Authorization) {
86+
return;
8187
}
88+
const resp = await axios.get(`/appointments?month=${month}`);
89+
return resp.data;
90+
} catch (error) {
91+
toast.error('Oops! Something went wrong. Please retry later', {
92+
duration: 3000,
93+
});
94+
}
8295
};
8396

84-
export const getAppointmentsByMonth = async (month) => {
85-
try {
86-
if(!axios.defaults.headers.common.Authorization) {
87-
return;
88-
}
89-
const resp = await axios.get(`/appointments?month=${month}`);
90-
return resp.data;
97+
export const updateAppointment = async (id, data) => {
98+
try {
99+
const response = await axios.put(`/appointments/${id}`, data);
100+
return response;
101+
} catch (error) {
102+
toast.error(`${error.message}`, {
103+
duration: 3000,
104+
});
105+
}
106+
};
91107

92-
} catch (error) {
93-
toast.error("Oops! Something went wrong. Please retry later", {
94-
duration: 3000,
95-
});
96-
}
97-
};
98-
99-
export const updateAppointment = async (id,data) => {
100-
try {
101-
const response = await axios.put(`/appointments/${id}`, data);
102-
return response;
103-
} catch (error) {
104-
toast.error(`${error.message}`, {
105-
duration: 3000,
106-
});
107-
}
108-
};
109-
110-
export const deleteAppointment = async (id) => {
111-
try {
112-
await axios.delete(`/appointments/${id}`);
113-
} catch (error) {
114-
toast.error(`${error.message}`, {
115-
duration: 3000,
116-
});
117-
}
118-
};
108+
export const deleteAppointment = async id => {
109+
try {
110+
await axios.delete(`/appointments/${id}`);
111+
} catch (error) {
112+
toast.error(`${error.message}`, {
113+
duration: 3000,
114+
});
115+
}
116+
};
119117

120-
export const sendFileToBackend = async (data) => {
118+
export const sendFileToBackend = async data => {
121119
try {
122120
const formData = new FormData();
123121
Object.entries(data).forEach(([key, value]) => {
@@ -133,12 +131,12 @@ export const sendFileToBackend = async (data) => {
133131
}
134132
};
135133

136-
export const bookAppointment = async (data) => {
137-
try {
134+
export const bookAppointment = async data => {
135+
try {
138136
const formData = new FormData();
139137
Object.entries(data).forEach(([key, value]) => {
140138
formData.append(key, value);
141-
});
139+
});
142140
const response = await axios.post('/appointments', formData);
143141
return response;
144142
} catch (error) {
@@ -148,11 +146,13 @@ export const bookAppointment = async (data) => {
148146
}
149147
};
150148

151-
export const getAvailableSlots = async(date,duration) => {
149+
export const getAvailableSlots = async (date, duration) => {
152150
try {
153-
const response = await axios.get(`/appointments/slots?date=${date}&duration=${duration}`);
151+
const response = await axios.get(
152+
`/appointments/slots?date=${date}&duration=${duration}`
153+
);
154154

155-
return response.data;
155+
return response.data;
156156
} catch (error) {
157157
toast.error(`${error.message}`, {
158158
duration: 3000,
@@ -161,19 +161,22 @@ export const getAvailableSlots = async(date,duration) => {
161161
};
162162

163163
export const getPublishableKey = async () => {
164-
try {
165-
const response = await axios.get('/stripe/config');
166-
return response.data.publishableKey;
167-
} catch (error) {
168-
console.error(error)
169-
}
164+
try {
165+
const response = await axios.get('/stripe/config');
166+
return response.data.publishableKey;
167+
} catch (error) {
168+
console.error(error);
169+
}
170170
};
171171

172172
export const createPaymentIntent = async (service, email) => {
173173
try {
174-
const response = await axios.post(`/stripe/create-payment-intent/${service}`, {email});
174+
const response = await axios.post(
175+
`/stripe/create-payment-intent/${service}`,
176+
{ email }
177+
);
175178
return response.data.clientSecret;
176179
} catch (error) {
177-
console.error(error)
180+
console.error(error);
178181
}
179-
};
182+
};

0 commit comments

Comments
 (0)