-
Notifications
You must be signed in to change notification settings - Fork 3
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
jigeol
committed
Nov 17, 2021
1 parent
ee22604
commit a9bd76a
Showing
22 changed files
with
179 additions
and
173 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
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
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
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
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
72 changes: 72 additions & 0 deletions
72
src/pages/CreateProduct/components/Footer/hooks/useSaveProduct.ts
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,72 @@ | ||
import { FAILED_TO_SAVE_PRODUCT } from 'constants/errors'; | ||
|
||
import { useCommonSnackbar } from 'components/CommonSnackbar/useCommonSnackbar'; | ||
import { usePost } from 'hooks/usePost'; | ||
import { | ||
currentProductIdAtom, | ||
currentProductInputAtom, | ||
currentStepAtom, | ||
} from 'pages/CreateProduct/recoils'; | ||
import { PAGE } from 'pages/CreateProduct/types'; | ||
import { useState } from 'react'; | ||
import { useRecoilValue, useSetRecoilState } from 'recoil'; | ||
import { splitText } from 'utils/splitText'; | ||
|
||
type SaveProduct = { | ||
saveProduct: () => void; | ||
}; | ||
|
||
export const useSaveProduct = (): SaveProduct => { | ||
const setCurrentStep = useSetRecoilState(currentStepAtom); | ||
const setCurrentProductId = useSetRecoilState(currentProductIdAtom); | ||
const [showError, setShowError] = useState(false); | ||
|
||
const { | ||
name, | ||
fullPrice, | ||
discountPrice, | ||
representativeImageUrl, | ||
specifiedSalesStartDate, | ||
specifiedSalesEndDate, | ||
tags, | ||
designIds, | ||
} = useRecoilValue(currentProductInputAtom); | ||
|
||
const onSuccess = () => { | ||
if (data) { | ||
setCurrentProductId(data.payload.id); | ||
} | ||
setCurrentStep(PAGE.INTRODUCTION); | ||
}; | ||
|
||
const { data, mutate } = usePost({ | ||
pathname: '/product/package', | ||
errorMessage: FAILED_TO_SAVE_PRODUCT, | ||
onSuccess, | ||
onError: () => setShowError(true), | ||
}); | ||
|
||
const saveProduct = (): void => { | ||
const postProductData = { | ||
id: null, | ||
name, | ||
full_price: fullPrice, | ||
discount_price: discountPrice, | ||
representative_image_url: representativeImageUrl, | ||
specified_sales_start_date: specifiedSalesStartDate, | ||
specified_sales_end_date: specifiedSalesEndDate, | ||
tags: splitText(tags, '#'), | ||
design_ids: designIds, | ||
}; | ||
|
||
mutate(postProductData); | ||
}; | ||
|
||
useCommonSnackbar({ | ||
message: FAILED_TO_SAVE_PRODUCT, | ||
severity: 'error', | ||
dependencies: [showError], | ||
}); | ||
|
||
return { saveProduct }; | ||
}; |
26 changes: 26 additions & 0 deletions
26
src/pages/CreateProduct/components/Footer/hooks/useStartSale.ts
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,26 @@ | ||
import { MY_INFORMATION_ROUTER_ROOT } from 'constants/path'; | ||
|
||
import { usePost } from 'hooks/usePost'; | ||
import { currentProductIdAtom } from 'pages/CreateProduct/recoils'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
type StartSale = { | ||
startSale: () => void; | ||
}; | ||
|
||
export const useStartSale = (): StartSale => { | ||
const currentProductId = useRecoilValue(currentProductIdAtom); | ||
const history = useHistory(); | ||
|
||
const { mutate } = usePost({ | ||
pathname: '/product', | ||
}); | ||
|
||
const startSale = () => { | ||
mutate({ id: currentProductId }); | ||
history.push(MY_INFORMATION_ROUTER_ROOT); | ||
}; | ||
|
||
return { startSale }; | ||
}; |
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
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.