Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…r-service into develop
  • Loading branch information
Joonhyung-Choi committed May 9, 2023
2 parents b515989 + 9e4b7b4 commit 56c2e0e
Show file tree
Hide file tree
Showing 27 changed files with 1,046 additions and 230 deletions.
268 changes: 268 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
"react-hook-form": "^7.43.0",
"react-icons": "^4.7.1",
"react-intersection-observer": "^9.4.3",
"react-modal": "^3.16.1",
"react-phone-number-input": "^3.2.17",
"react-query": "^3.39.3",
"react-scroll": "^1.8.9",
"react-scroll-wheel-handler": "^2.2.0",
"react-transition-group": "^4.4.5",
"recoil": "^0.7.7",
"styled-components": "^5.3.6",
"swiper": "^9.0.4",
"typescript": "4.9.4"
},
"devDependencies": {
"@types/react-modal": "^3.13.1"
}
}
15 changes: 9 additions & 6 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import styled from "styled-components";
import Router from "next/router";
import { GlobalStyle } from "../styles/global.style";
import type { AppProps } from "next/app";
import { Header } from "../src/components/header/Header";
import { Footer } from "../src/components/footer/Footer";
import { Layout } from "../src/components/layout/Layout";
import { RecoilRoot } from "recoil";
import { ScrollCSS } from "../src/components/layout/ScrollCSS";
import { QueryClient, QueryClientProvider } from "react-query";

export default function App({ Component, pageProps }: AppProps) {
const queryClient = new QueryClient();

return (
<RecoilRoot>
<Layout>
<Component {...pageProps} />
</Layout>
<QueryClientProvider client={queryClient}>
<Layout>
<Component {...pageProps} />
</Layout>
</QueryClientProvider>
</RecoilRoot>
);
}
8 changes: 8 additions & 0 deletions pages/admin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { NextPage } from "next";
import { AdminPage } from "../../src/components";

const Admin: NextPage = () => {
return <AdminPage />;
};

export default Admin;
8 changes: 8 additions & 0 deletions pages/admin/login/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { NextPage } from "next";
import { AdminLoginPage } from "../../../src/components";

const AdminLogin: NextPage = () => {
return <AdminLoginPage />;
};

export default AdminLogin;
11 changes: 5 additions & 6 deletions src/apis/api.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import axios from 'axios';
import applyDefaultParams from './applyDefaultParams';
import axios from "axios";
import applyDefaultParams from "./applyDefaultParams";

import normalizeAxiosError, {
SERVER_ERROR,
TIMEOUT_ERROR,
NETWORK_ERROR,
CLIENT_ERROR,
UNAUTH_ERROR,
} from './normalizeAxiosError';
import { settings } from '@street-vendor/core';
} from "./normalizeAxiosError";

const API_TIMEOUT = 50000; // 50s

Expand All @@ -19,13 +18,13 @@ const api = axios.create({
});

function getBaseUrl() {
return settings.api.baseUrl;
return "http://localhost:8080";
}

api.interceptors.request.use(applyDefaultParams);
api.interceptors.response.use(undefined, normalizeAxiosError);
api.interceptors.response.use(undefined, function (err) {
console.log('ERR :: ', err);
console.log("ERR :: ", err);

if (err.code === TIMEOUT_ERROR || err.code === NETWORK_ERROR) {
//
Expand Down
12 changes: 12 additions & 0 deletions src/apis/controller/signUp.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sendApi from "../sendApi";

export const SignUpApi = {
registerSignUp: async (data: FormData) => {
const response = await sendApi.post("/orders", data);
return response.data;
},
loadMeetings: async () => {
const response = await sendApi.get("/orders/meeting");
return response.data;
},
};
26 changes: 13 additions & 13 deletions src/apis/normalizeAxiosError.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { sessionService } from '../libs/sessionService';
import axios from 'axios';
import { tokenService } from "../libs/tokenService";
import axios from "axios";

export const UNAUTH_ERROR = 'UNAUTH_ERROR';
export const CLIENT_ERROR = 'CLIENT_ERROR';
export const SERVER_ERROR = 'SERVER_ERROR';
export const CANCEL_ERROR = 'CANCEL_ERROR';
export const TIMEOUT_ERROR = 'TIMEOUT_ERROR';
export const NETWORK_ERROR = 'NETWORK_ERROR';
export const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
export const UNAUTH_ERROR = "UNAUTH_ERROR";
export const CLIENT_ERROR = "CLIENT_ERROR";
export const SERVER_ERROR = "SERVER_ERROR";
export const CANCEL_ERROR = "CANCEL_ERROR";
export const TIMEOUT_ERROR = "TIMEOUT_ERROR";
export const NETWORK_ERROR = "NETWORK_ERROR";
export const UNKNOWN_ERROR = "UNKNOWN_ERROR";

function xhrError({ code, status = 0, data = {} }: any) {
const err: any = new Error();
err.name = 'XhrError';
err.name = "XhrError";
err.message = err.code = code;
err.data = data;
err.status = status;
Expand All @@ -20,7 +20,7 @@ function xhrError({ code, status = 0, data = {} }: any) {

export default function normalizeAxiosError(error: any) {
// timeout
if (error.code === 'ECONNABORTED') {
if (error.code === "ECONNABORTED") {
return xhrError({
code: TIMEOUT_ERROR,
});
Expand All @@ -37,8 +37,8 @@ export default function normalizeAxiosError(error: any) {
// service error, 400 401 404 500 502...
if (error.response) {
if ([401, 423].includes(error.response.status)) {
sessionService.resetIdSession();
location.replace('/login?warn');
// tokenService.resetToken();
location.replace("/login?warn");

return xhrError({
code: UNAUTH_ERROR,
Expand Down
26 changes: 13 additions & 13 deletions src/apis/sendApi.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
import { sessionService } from "../libs/sessionService";
import { tokenService } from "../libs/tokenService";
import api from "./api";

// eslint-disable-next-line import/no-anonymous-default-export
export default {
get: async (url: string, params?: any) => {
const idSession = await sessionService.getIdSession();
const token = await tokenService.getToken();

return params !== undefined
? api({
url: url,
method: "get",
params: params,
headers: {
Authorization: `${idSession}`,
Authorization: `${token}`,
},
})
: api({
url: url,
method: "get",
headers: {
Authorization: `${idSession}`,
Authorization: `${token}`,
},
});
},
post: async (url: string, params: any) => {
const idSession = await sessionService.getIdSession();
const token = await tokenService.getToken();

return params !== undefined
? api({
url: url,
method: "post",
data: params,
headers: {
Authorization: `${idSession}`,
Authorization: `${token}`,
},
})
: api({
url: url,
method: "post",
headers: {
Authorization: `${idSession}`,
Authorization: `${token}`,
},
});
},
put: async (url: string, params: any) => {
const idSession = await sessionService.getIdSession();
const token = await tokenService.getToken();

return params !== undefined
? api({
url: url,
method: "put",
params: params,
headers: {
Authorization: `${idSession}`,
Authorization: `${token}`,
},
})
: api({
url: url,
method: "put",
headers: {
Authorization: `${idSession}`,
Authorization: `${token}`,
},
});
},
delete: async (url: string, params?: any) => {
const idSession = await sessionService.getIdSession();
const token = await tokenService.getToken();

return params !== undefined
? api({
url: url,
method: "delete",
data: params,
headers: {
Authorization: `${idSession}`,
Authorization: `${token}`,
},
})
: api({
url: url,
method: "delete",
headers: {
Authorization: `${idSession}`,
Authorization: `${token}`,
},
});
},
Expand Down
Loading

0 comments on commit 56c2e0e

Please sign in to comment.