Skip to content

Commit

Permalink
♻️ 리팩토링 (#77-2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaewoong2 committed Nov 3, 2022
1 parent 59470b0 commit 6ad7243
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
26 changes: 26 additions & 0 deletions src/hooks/useToast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ToastOptionType, useToast as usePreviousToast } from '@jaewoong2/toast'

const useToast = (message: string, options?: ToastOptionType) => {
const suceess = usePreviousToast(message, {
backgroundColor: '#354898',
width: 200,
color: 'white',
borderRadius: 100,
...options,
})

const error = usePreviousToast(message, {
backgroundColor: '#E56FB4',
width: 200,
color: 'white',
borderRadius: 100,
...options,
})

return {
suceess,
error,
}
}

export default useToast
20 changes: 6 additions & 14 deletions src/pages/Configuration/hooks/useConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import useInput from '@/components/compounds/Form/hooks/useInput'
import useGetUser from '@/hooks/useGetUser'
import { useToast } from '@jaewoong2/toast'
import useToast from '@/hooks/useToast'
// import { useToast } from '@jaewoong2/toast'
import React, { useCallback } from 'react'
import { useNavigate } from 'react-router-dom'
import usePatchUser from './usePatchUser'

const useConfiguration = () => {
const [username, setUsername, onChangeUsername] = useInput()
const [userPhone, setUserPhone, onChangeUserPhone] = useInput()
const { show: successShow } = useToast('변경 완료', {
backgroundColor: '#354898',
width: 200,
color: 'white',
borderRadius: 100,
})

const { show: errorShow } = useToast('휴대폰 번호 양식을 지켜주세요 :)', {
backgroundColor: '#E56FB4',
const { suceess } = useToast('변경 완료')
const { error } = useToast('휴대폰 번호 양식을 지켜주세요 :)', {
width: 300,
color: 'white',
borderRadius: 100,
})

const { isLoading: userLoading } = useGetUser({
Expand All @@ -42,9 +34,9 @@ const useConfiguration = () => {
if (userPhone.length === 11) {
mutate({ username, userPhone })
navigate('/')
successShow()
suceess.show()
} else {
errorShow()
error.show()
}
},
[username, userPhone]
Expand Down
9 changes: 4 additions & 5 deletions src/pages/Edit/hooks/useEditMount.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import useGetUser from '@/hooks/useGetUser'
import { useToast } from '@jaewoong2/toast'
import useToast from '@/hooks/useToast'
import { useNavigate } from 'react-router-dom'
import useCompanyEditAction from './useCompanyEditAction'

const useEditMount = () => {
const navigate = useNavigate()
const { show } = useToast('로그인 후 이용하세요', {
type: 'warn',

const { error } = useToast('로그인 후 이용하세요', {
position: 'top',
subPosition: 'right',
color: 'white',
})

const { hanldeComapny } = useCompanyEditAction()
Expand All @@ -23,7 +22,7 @@ const useEditMount = () => {
hanldeComapny({ ...data })
},
onError: () => {
show()
error.show()
navigate(-1)
},
})
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Home/components/blocks/RecommandCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const RecommandCards = ({ title }: Props) => {
<div className="flex w-full gap-4 overflow-y-scroll pb-5">
{companies?.map((company) => (
<Card
key={company.id}
key={company.companyName}
companyDomain={encodeURIComponent(company.companyDomain ?? '')}
companyName={company.companyName}
profileImage={company.profileImage}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/Order/context/OrderContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useGetTemplate from '@/hooks/useGetTemplate'
import useStatus from '@/hooks/useStatus'
import useToast from '@/hooks/useToast'
import { Order } from '@/type'
import { useModal } from '@jaewoong2/modal'
import { AxiosError } from 'axios'
Expand All @@ -20,6 +21,7 @@ const OrderContextProvider = ({ children }: PropsWithChildren) => {
...defaultOrder,
templateId: id,
})
const { suceess } = useToast('제출 완료')

useGetTemplate(id ?? '', {
onSuccess: (data) => {
Expand Down Expand Up @@ -53,6 +55,7 @@ const OrderContextProvider = ({ children }: PropsWithChildren) => {
setCurrent(0)
setOrder({ ...defaultOrder, templateId: id })
navigate(`/${domain}`)
suceess.show()
},
onError: (err) => {
if (err.status === AxiosError.ECONNABORTED) {
Expand Down

0 comments on commit 6ad7243

Please sign in to comment.