Skip to content

Commit

Permalink
[#35] feat : Add URL component to manage url in single source
Browse files Browse the repository at this point in the history
  • Loading branch information
Seohyoung committed Jun 24, 2021
1 parent e351b57 commit 0e7b560
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
5 changes: 5 additions & 0 deletions FE/frontend/src/components/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Login = () => {
<a href={url}>
<GitHubLogin large>GitHub 계정으로 로그인</GitHubLogin>
</a>
<GoogleLogin large>Google 계정으로 로그인</GoogleLogin>
<TextInBetween sm>or</TextInBetween>
<ManualLogin large>아이디</ManualLogin>
<ManualLogin large>비밀번호</ManualLogin>
Expand Down Expand Up @@ -43,6 +44,10 @@ const GitHubLogin = styled(Buttons)`
background-color: ${props => props.theme.greyscale.titleActive};
`;

const GoogleLogin = styled(Buttons)`
background-color: #4285f4;
`;

const TextInBetween = styled(Typos)`
color: ${props => props.theme.greyscale.placeholer};
`;
Expand Down
5 changes: 3 additions & 2 deletions FE/frontend/src/components/login/Oauth.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect } from 'react';
import qs from 'qs';
import axios from 'axios';
import URL from '../../util/url';
import Main from '../main/Main';
import { RouteComponentProps } from 'react-router-dom';

Expand All @@ -15,11 +16,11 @@ const Oauth: React.FC<Props> = ({ history, location }) => {

try {
const response = await axios.get(
`http://52.78.35.48/api/login/github/web?code=${code}`
`${URL}/login/github/web?code=${code}`
);
localStorage.setItem('token', response.data.data.jwt);

axios.get('http://52.78.35.48/api/jwt', {
axios.get(`${URL}/jwt`, {
headers: { Authorization: 'Bearer ' + localStorage.getItem('token') },
});
history.push('/main');
Expand Down
3 changes: 3 additions & 0 deletions FE/frontend/src/util/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const URL = 'http://52.78.35.48/api';

export default URL;
18 changes: 9 additions & 9 deletions FE/frontend/src/util/useFetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from 'react-query';
import axios from 'axios';
const url = 'http://52.78.35.48/api';
import URL from './url';

interface Props {
id?: string;
Expand All @@ -23,46 +23,46 @@ const getData = async (type: string, action: string, filter?: Props) => {
case 'user':
switch (action) {
case 'image':
const userData = await axios.get(`${url}/user`, axiosConfig);
const userData = await axios.get(`${URL}/user`, axiosConfig);
return userData.data.data;
}
return;
case 'issue':
switch (action) {
case 'getAllData':
const allData = await axios.get(`${url}/issues`);
const allData = await axios.get(`${URL}/issues`);
return allData.data.data;
case 'count':
const count = await axios.get(`${url}/issues/count`);
const count = await axios.get(`${URL}/issues/count`);
return count.data.data;
case 'detail':
const detail = await axios.get(`${url}${filter?.id}`);
const detail = await axios.get(`${URL}${filter?.id}`);
return detail.data.data;
case 'filter':
const filteredData = await axios.get(
`${url}/issues?is_open=${filter?.isOpen}&filter=${filter?.specialFilter}&assignee=${filter?.assignee}&label=${filter?.label}&milestone=${filter?.milstone}&writer=${filter?.writer}`
`${URL}/issues?is_open=${filter?.isOpen}&filter=${filter?.specialFilter}&assignee=${filter?.assignee}&label=${filter?.label}&milestone=${filter?.milstone}&writer=${filter?.writer}`
);
return filteredData.data.data;
}
return;
case 'label':
switch (action) {
case 'getAllData':
const allData = await axios.get(`${url}/labels`);
const allData = await axios.get(`${URL}/labels`);
return allData.data.data;
}
return;
case 'milestone':
switch (action) {
case 'getAllData':
const allData = await axios.get(`${url}/milestones`);
const allData = await axios.get(`${URL}/milestones`);
return allData.data.data;
}
return;
case 'common':
switch (action) {
case 'count':
const count = await axios.get(`${url}/count`);
const count = await axios.get(`${URL}/count`);
return count.data.data;
}
}
Expand Down
22 changes: 11 additions & 11 deletions FE/frontend/src/util/useMutate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
const url = 'http://52.78.35.48/api';
import URL from './url';

interface Props {
data: unknown;
Expand All @@ -20,32 +20,32 @@ const useMutate =
case 'issue':
switch (action) {
case 'add':
return axios.post(`${url}/issues`, data, axiosConfig);
return axios.post(`${URL}/issues`, data, axiosConfig);
case 'close':
return axios.post(`${url}/issues/close`, data, axiosConfig);
return axios.post(`${URL}/issues/close`, data, axiosConfig);
case 'open':
return axios.post(`${url}/issues/open`, data, axiosConfig);
return axios.post(`${URL}/issues/open`, data, axiosConfig);
case 'delete':
return axios.delete(`${url}/issues/${id}`, axiosConfig);
return axios.delete(`${URL}/issues/${id}`, axiosConfig);
case 'editTitle':
return axios.patch(
`${url}/issues/${id}/title`,
`${URL}/issues/${id}/title`,
{
title: data,
},
axiosConfig
);
case 'editAssignees':
return axios.patch(
`${url}/issues/${id}/assignees`,
`${URL}/issues/${id}/assignees`,
data,
axiosConfig
);
case 'editLabels':
return axios.patch(`${url}/issues/${id}/labels`, data, axiosConfig);
return axios.patch(`${URL}/issues/${id}/labels`, data, axiosConfig);
case 'editMilestones':
return axios.patch(
`${url}/issues/${id}/milestones`,
`${URL}/issues/${id}/milestones`,
data,
axiosConfig
);
Expand All @@ -54,7 +54,7 @@ const useMutate =
case 'label':
switch (action) {
case 'add':
return axios.post(`${url}/labels`, data, axiosConfig);
return axios.post(`${URL}/labels`, data, axiosConfig);
}
return;
case 'milestone':
Expand All @@ -65,7 +65,7 @@ const useMutate =
switch (action) {
case 'add':
return axios.post(
`${url}/issues/${id}/comments`,
`${URL}/issues/${id}/comments`,
data,
axiosConfig
);
Expand Down

0 comments on commit 0e7b560

Please sign in to comment.