-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
296 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export interface MetaDefault { | ||
width: string; | ||
height: string; | ||
} | ||
|
||
export interface MetaDetail extends MetaDefault { | ||
x?: string; | ||
y?: string; | ||
|
||
z?: string; | ||
|
||
angle?: string; | ||
} | ||
|
||
export interface PrepareRequest { | ||
thumbnailMeta: MetaDefault; | ||
|
||
letterMeta: MetaDefault; | ||
|
||
backgroundMeta: MetaDefault; | ||
|
||
componentMetas: MetaDetail[]; | ||
} | ||
|
||
export interface PrepareResponse { | ||
thumbnailUrl: string; | ||
letterUrl: string; | ||
backgroundUrl: string; | ||
componentUrls: string[]; | ||
expires: number; | ||
sessionKey: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useState } from 'react'; | ||
import apiClient from '../common/http.client'; | ||
import ApiResponse from '../common/response'; | ||
import useErrorStore from '../store/error.store'; | ||
import useLoginStore from '@/store/login.store'; | ||
|
||
interface ProfileResponse { | ||
userId: string; | ||
email: string; | ||
nickName: string; | ||
} | ||
|
||
const useUserApi = () => { | ||
const { setError } = useErrorStore(); | ||
const { access } = useLoginStore(); | ||
const [profile, setProfile] = useState<ProfileResponse>(); | ||
const getProfile = async () => { | ||
const response = await apiClient.get<ApiResponse<ProfileResponse>>( | ||
`/user`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${access ?? ''}`, | ||
}, | ||
}, | ||
); | ||
if (!response.result) { | ||
setError(response.error); | ||
} else { | ||
setProfile(response.data); | ||
} | ||
}; | ||
|
||
return { profile, getProfile }; | ||
}; | ||
|
||
export default useUserApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { createContext, useContext, ReactNode, useEffect } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
import useLoginStore from '@/store/login.store'; | ||
|
||
const LoginContext = createContext<ReturnType<typeof useLoginStore> | null>( | ||
null, | ||
); | ||
|
||
export const LoginProvider = ({ children }: { children: ReactNode }) => { | ||
const router = useRouter(); | ||
const store = useLoginStore(); | ||
|
||
useEffect(() => { | ||
const { access } = store; | ||
|
||
if (!access && router.pathname !== '/page/login') { | ||
router.replace('/page/login'); | ||
} | ||
}, [store.access, router]); | ||
|
||
return ( | ||
<LoginContext.Provider value={store}>{children}</LoginContext.Provider> | ||
); | ||
}; | ||
|
||
export const useLogin = () => { | ||
const context = useContext(LoginContext); | ||
if (!context) { | ||
throw new Error('useLogin must be used within a LoginProvider'); | ||
} | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Button, Grid } from '@mantine/core'; | ||
import { useRouter } from 'next/router'; | ||
|
||
const Header = () => { | ||
const router = useRouter(); | ||
return ( | ||
<Grid> | ||
<Grid.Col span={4}> | ||
<Button onClick={() => router.replace('/page/my')}>MY</Button> | ||
</Grid.Col> | ||
<Grid.Col span={4}> | ||
<Button onClick={() => router.replace('/page/create')}>CREATE</Button> | ||
</Grid.Col> | ||
</Grid> | ||
); | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.