Skip to content

Commit

Permalink
Merge branch 'frontend' into feature/fe/#224-combine-map-and-canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
effozen authored Nov 21, 2024
2 parents febc9ab + caec07c commit 1aadab1
Show file tree
Hide file tree
Showing 22 changed files with 579 additions and 134 deletions.
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="ko">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="public/assets/favicon.svg" />
<link rel="icon" href="/assets/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>์„ ๋”ฐ๋ผ ๊ธธ๋”ฐ๋ผ - DDara</title>
</head>
Expand Down
37 changes: 33 additions & 4 deletions frontend/src/api/auth.api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getApiClient } from '@/api/client.api.ts';
import { ResponseDto } from '@/api/dto/response.dto.ts';
import { LoginResEntity } from '@/api/dto/auth.dto.ts';
import { LoginResEntity, RegisterResEntity } from '@/api/dto/auth.dto.ts';

export const doLogin = (id: string, password: string): Promise<ResponseDto<LoginResEntity>> => {
const promiseFn = (
Expand All @@ -11,11 +11,40 @@ export const doLogin = (id: string, password: string): Promise<ResponseDto<Login
apiClient
.post('/auth/login', { id, password })
.then(res => {
if (!res.data.success) {
if (res.status !== 200) {
console.error(res);
fnReject(`msg.${res.data.resultMsg}`);
fnReject(`msg.${res}`);
} else {
fnResolve(new ResponseDto<LoginResEntity>(res.data));
fnResolve(new ResponseDto<LoginResEntity>(res));
}
})
.catch(err => {
console.error(err);
fnReject('msg.RESULT_FAILED');
});
};
return new Promise(promiseFn);
};

export const doRegister = (
id: string,
name: string,
password: string,
email: string,
): Promise<ResponseDto<RegisterResEntity>> => {
const promiseFn = (
fnResolve: (value: ResponseDto<RegisterResEntity>) => void,
fnReject: (reason?: any) => void,
) => {
const apiClient = getApiClient();
apiClient
.post('/auth/register', { id, name, password, email })
.then(res => {
if (res.status !== 200) {
console.error(res);
fnReject(`msg.${res}`);
} else {
fnResolve(new ResponseDto<RegisterResEntity>(res));
}
})
.catch(err => {
Expand Down
57 changes: 57 additions & 0 deletions frontend/src/api/channel.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ResponseDto } from '@/api/dto/response.dto.ts';
import {
createChannelReqEntity,
createChannelResEntity,
getUserChannelsResEntity,
} from '@/api/dto/channel.dto.ts';
import { getApiClient } from '@/api/client.api.ts';

export const createChannel = (
data: createChannelReqEntity,
): Promise<ResponseDto<createChannelResEntity>> => {
const promiseFn = (
fnResolve: (value: ResponseDto<createChannelResEntity>) => void,
fnReject: (reason?: any) => void,
) => {
const apiClient = getApiClient();
apiClient
.post('/channel', data)
.then(res => {
if (res.status !== 200) {
console.error(res);
fnReject(`msg.${res}`);
} else {
fnResolve(new ResponseDto<createChannelResEntity>(res));
}
})
.catch(err => {
console.error(err);
fnReject('msg.RESULT_FAILED');
});
};
return new Promise(promiseFn);
};

export const getUserChannels = (userId: string): Promise<ResponseDto<getUserChannelsResEntity>> => {
const promiseFn = (
fnResolve: (value: ResponseDto<getUserChannelsResEntity>) => void,
fnReject: (reason?: any) => void,
) => {
const apiClient = getApiClient();
apiClient
.get(`/channel/user/${userId}`)
.then(res => {
if (res.status !== 200) {
console.error(res);
fnReject(`msg.${res}`);
} else {
fnResolve(new ResponseDto<getUserChannelsResEntity>(res));
}
})
.catch(err => {
console.error(err);
fnReject('msg.RESULT_FAILED');
});
};
return new Promise(promiseFn);
};
8 changes: 8 additions & 0 deletions frontend/src/api/dto/auth.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ export class LoginResEntity {

userId: string | undefined;
}

export class RegisterResEntity {
id: string | undefined;

name: string | undefined;

email: string | undefined;
}
59 changes: 59 additions & 0 deletions frontend/src/api/dto/channel.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export class locationEntity {
lat: number | undefined;

lng: number | undefined;
}

export class guestMarkerStyleEntity {
color: string | undefined;
}

export class guestEntity {
name: string | undefined;

start_location: locationEntity | undefined;

end_location: locationEntity | undefined;

path: locationEntity[] | undefined;

marker_style: guestMarkerStyleEntity | undefined;
}

export class createChannelReqEntity {
name: string | undefined;

host_id: string | undefined;

guests: guestEntity[] | undefined;
}

export class guestSimpleEntity {
id: string | undefined;

name: string | undefined;
}

export class createChannelResEntity {
id: string | undefined;

name: string | undefined;

host_id: string | undefined;

guests: guestSimpleEntity[] | undefined;

created_at: string | undefined;
}

export class channelListEntity {
id: string | undefined;

name: string | undefined;

generated_at: string | undefined;
}

export class getUserChannelsResEntity {
channels: channelListEntity[] | undefined;
}
49 changes: 32 additions & 17 deletions frontend/src/component/authmodal/AuthModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { Modal } from '@/component/common/modal/Modal';
import { doLogin } from '@/api/auth.api.ts';
import { doLogin, doRegister } from '@/api/auth.api.ts';
import { saveLocalData } from '@/utils/common/manageLocalData.ts';
import { AppConfig } from '@/constants.ts';

Expand Down Expand Up @@ -45,30 +45,45 @@ export const AuthModal = (props: IAuthModalProps) => {
}
};

const switchToRegister = () => {
setModalType('register');
};

const switchToLogin = () => {
setModalType('login');
};

const handleLoginClick = () => {
doLogin(loginData.id, loginData.pw).then(el => {
if (el.data?.token && el.data?.userId) {
saveLocalData(AppConfig.KEYS.LOGIN_TOKEN, el.data.token);
saveLocalData(AppConfig.KEYS.LOGIN_USER, el.data.userId);
}
window.location.reload();
});
doLogin(loginData.id, loginData.pw)
.then(el => {
if (el.data?.token && el.data?.userId) {
saveLocalData(AppConfig.KEYS.LOGIN_TOKEN, el.data.token);
saveLocalData(AppConfig.KEYS.LOGIN_USER, el.data.userId);
}
window.location.reload();
})
.catch(() => {
alert('์•„์ด๋””์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋‹ค์‹œ ํ™•์ธํ•ด์ฃผ์„ธ์š”.');
});
};

const handleSignUpClick = () => {
if (registerData.pw !== registerData.confirmPw) {
alert('๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');
return;
}
console.log('ํšŒ์›๊ฐ€์ž… ๋ฐ์ดํ„ฐ:', registerData);
};

const switchToRegister = () => {
setModalType('register');
};

const switchToLogin = () => {
setModalType('login');
doRegister(registerData.id, registerData.name, registerData.pw, registerData.email)
.then(el => {
if (el.data) {
alert('ํšŒ์›๊ฐ€์ž…์— ์„ฑ๊ณตํ–ˆ์Šต๋‹ˆ๋‹ค. ๋กœ๊ทธ์ธํ•ด์ฃผ์„ธ์š”.');
switchToLogin();
}
})
.catch(() => {
alert(
'ํšŒ์›๊ฐ€์ž…์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•ด์ฃผ์„ธ์š”.\nid๋Š” 4์ž ์ด์ƒ, ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” 6์ž๋ฆฌ ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.',
);
});
};

return (
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/component/header/HeaderBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import { useNavigate } from 'react-router-dom';
import { Button } from '@/component/common/button/Button.tsx';
import { useContext } from 'react';
import { FooterContext } from '../layout/footer/LayoutFooterProvider';
import { HeaderContext } from '../layout/header/LayoutHeaderProvider';

export const HeaderBackButton = () => {
const { resetFooterContext } = useContext(FooterContext);
const { resetHeaderContext } = useContext(HeaderContext);
const navigate = useNavigate();

const handleHeaderBackButtonClick = () => {
if (window.history.length > 1) {
resetFooterContext();
resetHeaderContext();
navigate(-1);
} else {
navigate('/');
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/component/layout/constant/HeaderConst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const HEADER_TITLE: Record<string, string> = {
'/add-channel/:user/draw': '์— ๋”ฐ๋ฅธ ๊ฒฝ๋กœ ์„ค์ •',
};

export const HEADER_SUBTITLE: Record<string, string> = {
'/add-channel/:user/draw': '์‚ฌ์šฉ์ž ๋ณ„๋กœ ์ถœ๋ฐœ์ง€/๋„์ฐฉ์ง€(๋งˆ์ปค), ๊ฒฝ๋กœ(๊ทธ๋ฆผ)์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค',
};

export const HEADER_LEFTBUTTON: Record<string, string> = {
'/add-channel': 'back',
'/add-channel/:user': 'back',
'/add-channel/:user/draw': 'back',
'/channel/:channelId/host': 'back',
'/register': 'back',
};

export const HEADER_RIGHTBUTTON: Record<string, string> = {
'/channel/:channelId/host': 'dropdown',
};
7 changes: 6 additions & 1 deletion frontend/src/component/layout/enumTypes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
export enum buttonActiveType {
export enum buttonActiveStyle {
'ACTIVE' = 'shadow-float text-gray-900',
'PASSIVE' = 'shadow-innerButton text-gray-400',
}

export enum buttonActiveType {
ACTIVE = 'active',
PASSIVE = 'passive',
}

export enum backgroundType {
'TRANSPARENCY' = '',
'WHITE' = 'bg-white',
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/component/layout/footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import classNames from 'classnames';
import { buttonActiveType } from '../enumTypes';
import { buttonActiveStyle, buttonActiveType } from '../enumTypes';

export interface IFooterProps {
title?: string;
onClick?: () => void;
active?: boolean;
active?: buttonActiveType;
isTranperency?: boolean;
}

export const Footer = (props: IFooterProps) => {
const buttonStyle = props.active ? buttonActiveType.ACTIVE : buttonActiveType.PASSIVE;
const buttonStyle =
props.active === buttonActiveType.ACTIVE ? buttonActiveStyle.ACTIVE : buttonActiveStyle.PASSIVE;
const handleClick = () => {
// ACTIVE ์ƒํƒœ์ผ ๋•Œ๋งŒ onClick ์‹คํ–‰
if (props.active === buttonActiveType.ACTIVE && props.onClick) {
props.onClick();
}
};

return props.isTranperency ? (
<div />
Expand All @@ -27,7 +34,7 @@ export const Footer = (props: IFooterProps) => {
buttonStyle,
)}
type="button"
onClick={props.onClick}
onClick={handleClick}
>
{props.title}
</button>
Expand Down
Loading

0 comments on commit 1aadab1

Please sign in to comment.