Skip to content

Commit

Permalink
🐛 post 요청시 기본 값이 넘어가도록 수정 (#65+)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaewoong2 committed Oct 21, 2022
1 parent abb13f8 commit a735927
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/pages/Order/components/blocks/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Order = () => {
img={content.img}
detailType={content.type}
answer={order.answers[current]}
questionTitle={`${content?.required && '(*)'} ${content.question}`}
questionTitle={`${content?.required ? '(*)' : ''} ${content.question}`}
options={content.options}
handleChangeOption={
content.type === 'multiObjective'
Expand All @@ -54,7 +54,7 @@ const Order = () => {
{content?.type === 'subjective' && (
<QuestionDescription
img={content.img}
questionTitle={`${content?.required && '(*)'} ${content.question}`}
questionTitle={`${content?.required ? '(*)' : ''} ${content.question}`}
handleChangeDescription={handleChangeTextArea(current)}
description={order.answers[current]}
/>
Expand Down
10 changes: 2 additions & 8 deletions src/pages/Order/components/blocks/Pickup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ import React from 'react'
import { Layout } from '@/components'
import { NavigationWithArrow } from '@/components/blocks'
import { FormControl, FormInput, FormLabel } from '@/components/compounds/Form/components'
import { getDateTime } from '@/utils'
import QuestionLayout from '../molecules/QuestionLayout'
import SubmitButton from '../molecules/SubmitButton'
import useOrderValueContext from '../../hooks/useOrderValueContext'
import useOrderActionContext from '../../hooks/useOrderActionContext'

const getDateTime = (date: Date) => {
return new Date(date.getTime() - date.getTimezoneOffset() * 60000)
.toISOString()
.split('.')[0]
.substring(0, 16)
}

const Pickup = () => {
const { order } = useOrderValueContext()
const { handlePickupdate, handleSubmit, handlePickupPhoneNumber } = useOrderActionContext()
Expand All @@ -33,7 +27,7 @@ const Pickup = () => {
<FormLabel className="p-1">픽업 날짜</FormLabel>
<FormInput
className="bordere flex w-full justify-between rounded-xl p-3"
value={order.pickupDate ?? getDateTime(new Date())}
value={order?.pickupDate ?? getDateTime(new Date())}
type="datetime-local"
onChange={handlePickupdate}
min={getDateTime(new Date())}
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Order/context/OrderContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext } from 'react'
import { Order } from '@/type'
import { Updater } from 'use-immer'
import { getDateTime } from '@/utils'

export type OrderAction = {
handleClickStep: (step: number) => () => void
Expand All @@ -18,6 +19,9 @@ export const defaultOrder: Order & { answers: string[][] } = {
templateId: '',
answers: [['']],
templateResponses: [],
pickupDate: getDateTime(new Date()),
image: '',
pickupNoticePhone: '',
}

const defaultAction: OrderAction = {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ export function useCurrentQueryString(url: string) {
getCurrentQueryString: (key: string) => searchParams.get(key),
}
}

export const getDateTime = (date: Date) => {
return new Date(date.getTime() - date.getTimezoneOffset() * 60000)
.toISOString()
.split('.')[0]
.substring(0, 16)
}

0 comments on commit a735927

Please sign in to comment.