-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FE] Feat/#502 #503
[FE] Feat/#502 #503
Changes from 53 commits
6298f48
a8cf622
5eee314
abc4701
12613e1
6f60cac
9c56123
5a1d2e1
592eba0
c82e138
d2e5331
9663453
c5df478
3684967
e8f2b48
5e583c5
47e2692
4c2e331
d5df4bb
06445d4
97c724e
631cb43
7da225e
7f42e70
41cd2b4
9434c4a
3d1fa9c
cb89ac1
d467f6e
84bbbdd
dfc723d
9758375
a126c4b
2726581
d2dabd4
c26bd75
94ebcba
ad3a293
836e0c4
2684205
94ab841
cd9eb67
bc7ba08
e6aba04
ec5ae7f
7d9906d
ade24b9
eeff372
d3b13ea
9d575f5
f954722
ea85f0f
85cd54e
b06ed24
5d5a93a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { patchApi } from '../apis/patchApi'; | ||
import useToast from '../hooks/useToast'; | ||
import { ContentTypeType } from '../types/Api'; | ||
|
||
interface fetchPutProps { | ||
url: string; | ||
payload: {}; | ||
errorMessage: string; | ||
contentType?: ContentTypeType; | ||
onSuccess?: () => void; | ||
isThrow?: boolean; | ||
} | ||
|
||
const usePatch = () => { | ||
const { showToast } = useToast(); | ||
|
||
const fetchPatch = async ({ | ||
url, | ||
payload, | ||
contentType, | ||
errorMessage, | ||
onSuccess, | ||
isThrow, | ||
}: fetchPutProps) => { | ||
try { | ||
const responseData = await patchApi(url, payload, contentType); | ||
|
||
if (onSuccess) { | ||
onSuccess(); | ||
} | ||
|
||
return responseData; | ||
} catch (e) { | ||
showToast('error', errorMessage); | ||
|
||
if (isThrow) throw e; | ||
} | ||
}; | ||
|
||
return { fetchPatch }; | ||
}; | ||
|
||
export default usePatch; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { DEFAULT_PROD_URL } from '../constants'; | ||
import { ContentTypeType } from '../types/Api'; | ||
import withTokenRefresh from './utils'; | ||
|
||
export const patchApi = async ( | ||
url: string, | ||
data: {}, | ||
contentType?: ContentTypeType, | ||
) => { | ||
return await withTokenRefresh(async () => { | ||
const apiUrl = `${DEFAULT_PROD_URL + url}`; | ||
const userToken = localStorage.getItem('userToken'); | ||
const headers: any = { | ||
'content-type': 'application/json', | ||
}; | ||
|
||
if (userToken) { | ||
headers['Authorization'] = `Bearer ${userToken}`; | ||
} | ||
|
||
if (contentType) { | ||
headers['content-type'] = contentType; | ||
} | ||
|
||
const response = await fetch(apiUrl, { | ||
method: 'PATCH', | ||
headers, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
if (response.status >= 400) { | ||
throw new Error('[SERVER] PUT 요청에 실패했습니다.'); | ||
} | ||
|
||
return response; | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import styled from 'styled-components'; | ||
import theme from '../../../themes'; | ||
|
||
export type ButtonVariant = 'primary' | 'secondary'; | ||
export type ButtonVariant = 'primary' | 'secondary' | 'custom'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 이거 custom은 로그아웃 버튼이 너무 커서 만드신 걸까요?!!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. YES |
||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
|
@@ -14,11 +14,19 @@ const variants = { | |
color: `${theme.color.white}`, | ||
backgroundColor: `${theme.color.primary}`, | ||
border: `1px solid ${theme.color.primary}`, | ||
padding: `${theme.spacing['2']} ${theme.spacing['3']}`, | ||
}, | ||
secondary: { | ||
color: `${theme.color.primary}`, | ||
backgroundColor: 'transparent', | ||
border: `1px solid ${theme.color.primary}`, | ||
padding: `${theme.spacing['2']} ${theme.spacing['3']}`, | ||
}, | ||
custom: { | ||
color: `${theme.color.white}`, | ||
backgroundColor: `${theme.color.primary}`, | ||
border: `1px solid ${theme.color.primary}`, | ||
padding: `${theme.spacing['0']} ${theme.spacing['2']}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이쯤되면 버튼도 Text 마냥 처리해야할수도.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 밑에 달았는데 비슷한 생각입니다 세인! 새로운 버튼 생길 때마다 바꿔줄 수는 없을 것 같아서! 나중에 같이 수정해보죠 !! |
||
}, | ||
}; | ||
|
||
|
@@ -31,7 +39,8 @@ const Button = styled.button<ButtonProps>` | |
border: ${({ variant }) => variants[variant].border}; | ||
opacity: ${({ disabled }) => (disabled ? 0.5 : 1)}; | ||
border-radius: ${({ theme }) => theme.radius.small}; | ||
padding: ${({ theme }) => `${theme.spacing['2']} ${theme.spacing['3']}`}; | ||
padding: ${({ variant }) => | ||
variants[variant].padding || `${theme.spacing['2']} ${theme.spacing['3']}`}; | ||
font-size: ${({ theme }) => theme.fontSize.small}; | ||
|
||
&:hover { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export interface ProfileProps { | ||
name: string; | ||
email: string; | ||
image: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생각해보니 저희가 patch가 없었군요..! 새로 만드신거 너무 좋습니다! 굿굿 !!!!