Skip to content

Commit

Permalink
Merge pull request #266 from AnotherUniverseAU/DongHyuk
Browse files Browse the repository at this point in the history
FEAT: Admin Page To Send Marketing Message
  • Loading branch information
cucumber5252 authored May 26, 2024
2 parents 7d48b56 + 98a06bc commit 0854f4f
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 349 deletions.
75 changes: 35 additions & 40 deletions src/apis/apiRequestGet.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,45 @@
import { getNewToken } from "src/apis/getNewToken";
import { AuthVerify } from "./authVerify";
import type { InternalAxiosRequestConfig } from "axios";
import axios from "axios";
import sendAccessTokenToApp from "./sendAccessTokenToApp";
import { getNewToken } from 'src/apis/getNewToken';
import { AuthVerify } from './authVerify';
import type { InternalAxiosRequestConfig } from 'axios';
import axios from 'axios';
import sendAccessTokenToApp from './sendAccessTokenToApp';

const BASE_URL = process.env.REACT_APP_BASE_URL;
// const refresh = localStorage.getItem("refreshToken");

export const apiRequestGet = async (path: string) => {
const accessToken = (await localStorage.getItem("accessToken")) as string;
const customHttp = axios.create({
baseURL: `${BASE_URL}`,
timeout: 8000,
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const accessToken = (await localStorage.getItem('accessToken')) as string;
const customHttp = axios.create({
baseURL: `${BASE_URL}`,
timeout: 8000,
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

const onFulfilled = async (config: InternalAxiosRequestConfig) => {
const token_validate = await AuthVerify();
if (
token_validate === "Access Token Expired" ||
token_validate === "None Access Token"
) {
const newAccessToken = await getNewToken();
await sendAccessTokenToApp(newAccessToken);
if (config.headers) {
config.headers.Authorization = `Bearer ${newAccessToken}`;
}
}
return config;
};
const onFulfilled = async (config: InternalAxiosRequestConfig) => {
const token_validate = await AuthVerify();
if (token_validate === 'Access Token Expired' || token_validate === 'None Access Token') {
const newAccessToken = await getNewToken();
await sendAccessTokenToApp(newAccessToken);
if (config.headers) {
config.headers.Authorization = `Bearer ${newAccessToken}`;
}
}
return config;
};

customHttp.interceptors.request.use(onFulfilled, (err) =>
Promise.reject(err)
);
customHttp.interceptors.request.use(onFulfilled, (err) => Promise.reject(err));

try {
const response = await customHttp.get(path);
if (response.status >= 200 && response.status < 300) {
console.log(`[GET] Data received from ${path}:`, response.data);
return response.data;
} else {
console.error(`[GET] Failed to get data from ${path}:`, response.data);
try {
const response = await customHttp.get(path);
if (response.status >= 200 && response.status < 300) {
console.log(`[GET] Data received from ${path}:`, response.data);
return response.data;
} else {
console.error(`[GET] Failed to get data from ${path}:`, response.data);
}
} catch (error) {
console.error(`[GET] Error fetching data from ${path}:`, error);
}
} catch (error) {
console.error(`[GET] Error fetching data from ${path}:`, error);
}
};
4 changes: 2 additions & 2 deletions src/components/auth/autoRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const RouterInfo: RouterItem[] = [
element: <EachNicknameEdit />,
withAuthorization: true,
},
{ path: '/au_admin_2023', element: <Admin />, withAuthorization: true },
{ path: '/au_admin_send', element: <SendMessage />, withAuthorization: true },
{ path: '/au_admin_2023', element: <Admin />, withAuthorization: false },
{ path: '/au_admin_send', element: <SendMessage />, withAuthorization: false },
{ path: '/', element: <Main />, withAuthorization: true },
{
path: '/noticeDetail',
Expand Down
4 changes: 2 additions & 2 deletions src/pages/chat/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { apiRequestGet } from 'src/apis/apiRequestGet';
import { Loading } from 'src/pages/setting/loading.tsx';
import { BackgroundFull } from 'src/components/background/background';

import { CensorText } from 'src/components/censorText';
// import { CensorText } from 'src/components/censorText';

interface Chat {
name: string;
Expand Down Expand Up @@ -50,7 +50,7 @@ const ChatListComponent = ({ chatRoomDatas }: ChatListProps) => {
</S.ChatImgWrapper>
<S.ChatContent>
<S.ChatName>{chat.name}</S.ChatName>
<S.ChatText>{CensorText(chat.lastChat)}</S.ChatText>
<S.ChatText>{chat.lastChat}</S.ChatText>
</S.ChatContent>
<S.ChatSubContent>
<S.ChatTime>
Expand Down
Loading

0 comments on commit 0854f4f

Please sign in to comment.