-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from zestlee1106/feature/api-fix
Feature/api fix
- Loading branch information
Showing
19 changed files
with
538 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Room, RoomPost } from '@/public/types/room'; | ||
import { fetchData } from './index-dev'; | ||
|
||
export const fetchRooms = async () => { | ||
return fetchData<Room[]>('/api/room'); | ||
}; | ||
|
||
export const fetchRoom = async (id: string) => { | ||
return fetchData<Room>(`/api/room/${id}`); | ||
}; | ||
|
||
export const fetchPostRoom = async (data: RoomPost) => { | ||
return fetchData<RoomPost>(`/api/v1/rooms`); | ||
}; |
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 |
---|---|---|
@@ -1,15 +1,6 @@ | ||
import { Room, RoomPost } from '@/public/types/room'; | ||
import { fetchData } from './index-dev'; | ||
import { Furnishing } from '@/public/types/room'; | ||
import { fetchData } from './index'; | ||
|
||
|
||
export const fetchRooms = async () => { | ||
return fetchData<Room[]>('/api/room'); | ||
}; | ||
|
||
export const fetchRoom = async (id: string) => { | ||
return fetchData<Room>(`/api/room/${id}`); | ||
export const fetchFurnishings = async () => { | ||
return fetchData<Furnishing[]>('/api/v1/furnishings'); | ||
}; | ||
|
||
export const fetchPostRoom = async(data: RoomPost) => { | ||
return fetchData<RoomPost>(`/api/v1/rooms`); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useCallback, useEffect, useMemo } from 'react'; | ||
import { UseFormRegisterReturn } from 'react-hook-form'; | ||
import Button from '../Button/Button'; | ||
import { Option } from '../Radio/Radio'; | ||
|
||
interface MultiButtonProps { | ||
options: Option[]; | ||
register: UseFormRegisterReturn; | ||
onChange?: (value: string) => void; | ||
} | ||
|
||
function MultiButton({ options, register }: MultiButtonProps) { | ||
const [selected, setSelected] = React.useState<Option>(); | ||
|
||
const handleButtonClick = (value: string) => { | ||
const selectedButton = options.find((option) => option.value === value); | ||
|
||
if (!selectedButton) { | ||
return; | ||
} | ||
|
||
setSelected(selectedButton); | ||
}; | ||
|
||
const getButtonColor = useCallback( | ||
(value: string) => { | ||
return selected?.value === value ? 'r1' : 'outlined'; | ||
}, | ||
[selected] | ||
); | ||
|
||
useEffect(() => { | ||
const customEvent = { | ||
target: { | ||
name: register.name, | ||
value: selected, | ||
}, | ||
}; | ||
register.onChange(customEvent); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [selected]); | ||
|
||
useEffect(() => { | ||
setSelected(options[0]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
<div className={`mb-3 grid gap-0 grid-cols-${options.length}`}> | ||
{options.map((option, index) => ( | ||
<div key={`option-${index}`} className="col-span-1"> | ||
<Button | ||
size="lg" | ||
type="button" | ||
onClick={() => handleButtonClick(option.value)} | ||
color={getButtonColor(option.value)} | ||
> | ||
{option.label} | ||
</Button> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default MultiButton; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.sub-header { | ||
@apply font-pretendard font-semibold text-[16px]; | ||
} |
Oops, something went wrong.