diff --git a/src/apis/auth/Auth.api.js b/src/apis/auth/AuthApi.js similarity index 58% rename from src/apis/auth/Auth.api.js rename to src/apis/auth/AuthApi.js index 4049978..c9da1d7 100644 --- a/src/apis/auth/Auth.api.js +++ b/src/apis/auth/AuthApi.js @@ -1,11 +1,11 @@ -const { default: axios, Axios } = require("axios"); -const { default: InstanceSetting } = require("../common/instance.api"); +const { default: axios, Axios } = require('axios'); +const { default: InstanceSetting } = require('../common/instance.api'); // axios.defaults.baseURL = "https://api.gosrock.band"; class AuthApi extends InstanceSetting { constructor() { - super("https://api.gosrock.band/v1/auth"); + super('https://api.gosrock.band/v1/auth'); } // { // "phoneNumber": "string", @@ -13,9 +13,9 @@ class AuthApi extends InstanceSetting { // } requestSlackValidationNumber = async ({ phoneNumber, slackEmail }) => { - return await this.axiosInstance.post("/slack/send", { + return await this.axiosInstance.post('/slack/send', { phoneNumber, - slackEmail, + slackEmail }); }; @@ -28,13 +28,13 @@ class AuthApi extends InstanceSetting { validationSlackNumber = async ({ phoneNumber, slackEmail, - validationNumber, + validationNumber }) => { - return await this.axiosInstance.post("/slack/validation", { + return await this.axiosInstance.post('/slack/validation', { phoneNumber, slackEmail, - validationNumber, + validationNumber }); }; } -module.exports = new AuthApi(); +export default new AuthApi(); diff --git a/src/apis/tickets/Tickets.api.js b/src/apis/tickets/Tickets.api.js deleted file mode 100644 index be3ff08..0000000 --- a/src/apis/tickets/Tickets.api.js +++ /dev/null @@ -1,19 +0,0 @@ -const { default: axios } = require("axios"); - -// axios.defaults.baseURL = "https://api.gosrock.band"; -const { default: InstanceSetting } = require("../common/instance.api"); - -class TicketsApi extends InstanceSetting { - constructor() { - super("https://api.gosrock.band/v1/tickets"); - } - - // 예시임다 - getTickets = async ({ phoneNumber, slackEmail }) => { - await this.axiosInstance.post("/slack/send", { - phoneNumber, - slackEmail, - }); - }; -} -module.exports = new TicketsApi(); diff --git a/src/apis/tickets/TicketsApi.js b/src/apis/tickets/TicketsApi.js new file mode 100644 index 0000000..05ce0e0 --- /dev/null +++ b/src/apis/tickets/TicketsApi.js @@ -0,0 +1,19 @@ +const { default: axios } = require('axios'); + +// axios.defaults.baseURL = "https://api.gosrock.band"; +const { default: InstanceSetting } = require('../common/instance.api'); + +class TicketsApi extends InstanceSetting { + constructor() { + super('https://api.gosrock.band/v1/tickets'); + } + + // 예시임다 + getTickets = async ({ phoneNumber, slackEmail }) => { + await this.axiosInstance.post('/slack/send', { + phoneNumber, + slackEmail + }); + }; +} +export default new TicketsApi(); diff --git a/src/state/actions-creators/logout.js b/src/state/actions-creators/logout.js index 0c73db0..88cccff 100644 --- a/src/state/actions-creators/logout.js +++ b/src/state/actions-creators/logout.js @@ -1,18 +1,18 @@ -import { LOGOUT_USER } from "../action-types/logout"; -import axios from "axios"; -import history from "../../history"; -import ticketsApi from "../../apis/tickets/tickets.api"; +import { LOGOUT_USER } from '../action-types/logout'; +import axios from 'axios'; +import history from '../../history'; +import TicketsApi from '../../apis/tickets/TicketsApi'; -export const logout = (callback) => async (dispatch) => { +export const logout = callback => async dispatch => { dispatch({ type: LOGOUT_USER }); - localStorage.setItem("accessToken", null); + localStorage.setItem('accessToken', null); axios.defaults.headers.common.Authorization = null; // 자동으로 피쳐로 넘어가게끔 - history.push("/auth/login"); - ticketsApi.expireAccessTokne(); - console.log(ticketsApi.axiosInstance.defaults.headers); + history.push('/auth/login'); + TicketsApi.expireAccessTokne(); + console.log(TicketsApi.axiosInstance.defaults.headers); callback(); }; diff --git a/src/state/actions-creators/slackMessage.js b/src/state/actions-creators/slackMessage.js index 163e483..63addb0 100644 --- a/src/state/actions-creators/slackMessage.js +++ b/src/state/actions-creators/slackMessage.js @@ -1,16 +1,17 @@ -import axios from "axios"; -import authApi from "../../apis/auth/auth.api"; -import ErrorResponse from "../../apis/common/ErrorResponse"; +import axios from 'axios'; +import AuthApi from '../../apis/auth/AuthApi'; + +import ErrorResponse from '../../apis/common/ErrorResponse'; import { SLACK_MESSAGE_PENDING, SLACK_MESSAGE_SUCCESS, - SLACK_MESSAGE_FAIL, -} from "../action-types"; + SLACK_MESSAGE_FAIL +} from '../action-types'; export const slackMessage = ({ phoneNumber, slackEmail }, callback) => - async (dispatch) => { + async dispatch => { try { dispatch({ type: SLACK_MESSAGE_PENDING }); @@ -19,9 +20,9 @@ export const slackMessage = // "slackEmail": "water0641@naver.com" // } - const response = await authApi.requestSlackValidationNumber({ + const response = await AuthApi.requestSlackValidationNumber({ phoneNumber, - slackEmail, + slackEmail }); // const response = await axios.post( // "https://api.gosrock.band/v1/auth/slack/send", @@ -30,19 +31,18 @@ export const slackMessage = // slackEmail, // } // ); - - console.log(response); + // console.log(response); dispatch({ type: SLACK_MESSAGE_SUCCESS, - payload: response.data.data.validationNumber, + payload: response.data.data.validationNumber }); callback(); } catch (e) { dispatch({ type: SLACK_MESSAGE_FAIL, - payload: new ErrorResponse(e.response.data.error), + payload: new ErrorResponse(e.response.data.error) }); } }; diff --git a/src/state/actions-creators/slackValidation.js b/src/state/actions-creators/slackValidation.js index ad4cb44..3db8091 100644 --- a/src/state/actions-creators/slackValidation.js +++ b/src/state/actions-creators/slackValidation.js @@ -1,36 +1,39 @@ -import axios from "axios"; -import authApi from "../../apis/auth/auth.api"; -import ErrorResponse from "../../apis/common/ErrorResponse"; -import ticketsApi from "../../apis/tickets/tickets.api"; +import axios from 'axios'; +import AuthApi from '../../apis/auth/AuthApi'; + +import ErrorResponse from '../../apis/common/ErrorResponse'; +import TicketsApi from '../../apis/tickets/TicketsApi'; + import { SLACK_VALIDATION_PENDING, SLACK_VALIDATION_SUCCESS, - SLACK_VALIDATION_FAIL, -} from "../action-types"; + SLACK_VALIDATION_FAIL +} from '../action-types'; export const slackValidation = ({ phoneNumber, slackEmail, validationNumber }, callback) => - async (dispatch) => { + async dispatch => { try { dispatch({ type: SLACK_VALIDATION_PENDING }); - const response = await authApi.validationSlackNumber({ + const response = await AuthApi.validationSlackNumber({ phoneNumber, slackEmail, - validationNumber, + validationNumber }); console.log(response.data.data); dispatch({ type: SLACK_VALIDATION_SUCCESS, - payload: response.data.data, + payload: response.data.data }); - localStorage.setItem("accessToken", response.data.data.accessToken); + localStorage.setItem('accessToken', response.data.data.accessToken); axios.defaults.headers.common.Authorization = response.data.data.accessToken; // 나중에 api instance 가 늘어났다 이거 설정 해줘야함!!! - ticketsApi.changeInstanceDefaultHeaders(response.data.data.accessToken); + + TicketsApi.changeInstanceDefaultHeaders(response.data.data.accessToken); callback(); } catch (e) { @@ -39,7 +42,7 @@ export const slackValidation = alert(e.response.data.message); dispatch({ type: SLACK_VALIDATION_FAIL, - payload: new ErrorResponse(e.response.data.error), + payload: new ErrorResponse(e.response.data.error) }); } };