Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat#100 search/autosuggestion #101

Merged
merged 4 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/app/shopinfo/CardList.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@import '@/styles/_media';

.layout {
display: grid;
place-items: center;
width: 100%;
grid-template-columns: repeat(3, 1fr);
gap: 1.4rem;
}

@include media(tablet) {
.cardList {
grid-template-columns: repeat(2, 1fr);
}
}
31 changes: 31 additions & 0 deletions src/app/shopinfo/CardList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { NoticeDataType, ShopDataType } from '@/types';
import Card from '@/components/common/Card';
import Cookies from 'js-cookie';
import raisePercent from '@/utils/getRaisePercent';

import styles from './CardList.module.scss';
export default function CardList({ noticeList, shopData }: { noticeList: NoticeDataType[]; shopData: ShopDataType }) {
const shopId = Cookies.get('shopId');
return (
<div className={styles.layout}>
{noticeList.map((notice) => (
<Card
key={notice.item.id}
title={shopData.name}
image={shopData.imageUrl}
startTime={notice.item.startsAt}
workHour={notice.item.workhour}
salary={notice.item.hourlyPay}
raise={shopData ? raisePercent(notice.item.hourlyPay, shopData.originalHourlyPay) : 0}
isRaised={notice?.item.hourlyPay > shopData?.originalHourlyPay}
location={shopData.address1}
shopId={shopId}
completed={
notice?.item.closed ? '๋ชจ์ง‘ ์™„๋ฃŒ' : new Date() > new Date(notice?.item.startsAt) ? '์ง€๋‚œ ๊ณต๊ณ ' : ''
}
noticeId={notice.item.id}
/>
))}
</div>
);
}
87 changes: 16 additions & 71 deletions src/app/shopinfo/ShopInformation.tsx
Original file line number Diff line number Diff line change
@@ -1,97 +1,42 @@
import Image from 'next/image';
import { GPS } from '@/utils/constants';
import { NoticeDataType, NoticeSearchDataType } from '@/types';
import { useContext, useEffect, useState } from 'react';
import Registration from '@/components/shopinfoPage/Registartion';
import OwnerAddNotice from '@/components/ownerAddNotice/OwnerAddNotice';
import MyShop from '@/components/shopinfoPage/MyShop';
import NoticeRegistration from '@/components/shopinfoPage/NoticeRegistration';
import Cookies from 'js-cookie';
import Button from '@/components/common/Button';
import BASE_URL from '@/constants/BASEURL';
import Card from '@/components/common/Card';
import raisePercent from '@/utils/getRaisePercent';
import { ShopDataContext } from '@/context/ShopDataContext';
import styles from './page.module.scss';
import CardList from './CardList';

export default function ShopInformation() {
const [showShopEdit, setShowShopEdit] = useState(false);
const [showAddNotice, setShowAddNotice] = useState(false);
const { shopData } = useContext(ShopDataContext);
const { shopData, updateShopData } = useContext(ShopDataContext);
const [noticeList, setNoticeList] = useState<NoticeDataType[] | []>([]);
const shopId = Cookies.get('shopId') || '';
const hasNoticeList = noticeList.length !== 0;

useEffect(() => {
const fetchData = async () => {
const fetchShopData = async () => {
const result = await fetch(`${BASE_URL}/shops/${shopId}`);
const data = await result.json();
updateShopData(data.item);
};

const fetchNoticeData = async () => {
const response = await fetch(`${BASE_URL}/shops/${shopId}/notices`);
const data: NoticeSearchDataType = await response.json();
setNoticeList(data.items);
};
fetchData();

fetchShopData();
fetchNoticeData();
}, [shopId]);

return (
<div className={styles.layout}>
<h2 className={styles.title}>๋‚ด ๊ฐ€๊ฒŒ</h2>
<section className={styles.shopLayout}>
<article className={styles.shopBox}>
<Image className={styles.mainImage} src={shopData.imageUrl} alt="shop" width={150} height={150} />
<div className={styles.shopInfoBox}>
<p className={styles.label}>์‹๋‹น</p>
<h1 className={styles.name}>{shopData.name}</h1>
<p className={styles.address1}>
<Image src={GPS} alt="location" width={25} height={25} />
{shopData.address1}
</p>
<p className={styles.description}>{shopData.description}</p>
<div className={styles.buttonBox}>
<Button color="white" size="medium" onClick={() => setShowShopEdit(true)}>
ํŽธ์ง‘ํ•˜๊ธฐ
</Button>
<Button color="orange" size="medium" onClick={() => setShowAddNotice(true)}>
๊ณต๊ณ  ๋“ฑ๋กํ•˜๊ธฐ
</Button>
</div>
</div>
</article>
</section>
{showShopEdit && <Registration onClose={() => setShowShopEdit(false)} />}
{showAddNotice && (
<div className={styles.modalBox}>
<OwnerAddNotice onClose={() => setShowAddNotice(false)} />
</div>
)}
<MyShop shopData={shopData} />
<section>
<h2 className={styles.title}>๋“ฑ๋กํ•œ ๊ณต๊ณ </h2>
{hasNoticeList ? (
<div className={styles.cardList}>
{noticeList.map((notice) => (
<Card
key={notice.item.id}
title={shopData.name}
image={shopData.imageUrl}
startTime={notice.item.startsAt}
workHour={notice.item.workhour}
salary={notice.item.hourlyPay}
raise={shopData ? raisePercent(notice.item.hourlyPay, shopData.originalHourlyPay) : 0}
location={shopData.address1}
shopId={shopId}
completed={
notice?.item.closed ? '๋ชจ์ง‘ ์™„๋ฃŒ' : new Date() > new Date(notice?.item.startsAt) ? '์ง€๋‚œ ๊ณต๊ณ ' : ''
}
noticeId={notice.item.id}
/>
))}
</div>
) : (
<article className={styles.registerLayout}>
<p>๊ณต๊ณ ๋ฅผ ๋“ฑ๋กํ•ด ๋ณด์„ธ์š”</p>
<div className={styles.registerButton}>
<Button color="orange" size="medium" onClick={() => setShowAddNotice(true)}>
๊ณต๊ณ  ๋“ฑ๋กํ•˜๊ธฐ
</Button>
</div>
</article>
)}
{hasNoticeList ? <CardList noticeList={noticeList} shopData={shopData} /> : <NoticeRegistration />}
</section>
</div>
);
Expand Down
10 changes: 7 additions & 3 deletions src/app/shopinfo/ShopRegistration.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState } from 'react';
import Registration from '@/components/shopinfoPage/Registartion';
import Registration from '@/components/shopinfoPage/Registration';
import Button from '@/components/common/Button';
import styles from './page.module.scss';

export default function ShopRegistration() {
const [showShopRegistartion, setShowShopRegisteration] = useState(false);
const [showShopRegistration, setShowShopRegisteration] = useState(false);
return (
<section className={styles.layout}>
<h2 className={styles.title}>๋‚ด ๊ฐ€๊ฒŒ</h2>
Expand All @@ -15,7 +15,11 @@ export default function ShopRegistration() {
๊ฐ€๊ฒŒ ๋“ฑ๋กํ•˜๊ธฐ
</Button>
</div>
{showShopRegistartion && <Registration onClose={() => setShowShopRegisteration(false)} />}
{showShopRegistration && (
<div className={styles.modalBox}>
<Registration onClose={() => setShowShopRegisteration(false)} />
</div>
)}
</article>
</section>
);
Expand Down
16 changes: 15 additions & 1 deletion src/app/shopinfo/layout.module.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
@import '@/styles/_media.scss';

.layout {
width: 100%;
display: flex;
align-items: center;
flex-direction: column;
min-height: 100vh;
position: relative;
}

.box {
display: flex;
width: 100%;
max-width: 1200px;
flex-direction: column;
align-items: center;
flex-grow: 1;
position: relative;
padding: 0 6rem;
}

@include media(mobile) {
.box {
margin: 0 1rem;
}
}
6 changes: 2 additions & 4 deletions src/app/shopinfo/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ export default function shopInfoLayout({ children }: { children: React.ReactNode
<ShopDataContextProvider>
<div className={styles.layout}>
<Header />
<div className={styles.box}>
{children}
<Footer />
</div>
<div className={styles.box}>{children}</div>
<Footer />
</div>
</ShopDataContextProvider>
);
Expand Down
75 changes: 3 additions & 72 deletions src/app/shopinfo/page.module.scss
Original file line number Diff line number Diff line change
@@ -1,79 +1,10 @@
@import '@/styles/_index';
@import '@/styles/_media';

.layout {
width: 100%;
font-size: 1.6rem;
padding: 3rem;
flex-grow: 1;
}

.title {
margin: 3rem 0;
}

.shopLayout {
background: $red-600;
padding: 2.6rem;
@include rounded-xl;
}

.shopBox {
display: flex;
gap: 1.6rem;
}

.shopInfoBox {
width: 100%;
display: flex;
flex-direction: column;
gap: 1rem;
}

.mainImage {
@include rounded-lg;
}

.label {
color: $red-400;
@include font-bold;
}

.address1 {
display: flex;
align-items: center;
color: $gray-500;
}

.buttonBox {
display: flex;
gap: 3rem;
}

.registerLayout {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: 1px solid $gray-400;
padding: 10rem;
gap: 3rem;
}

.registerButton {
width: 100%;
padding: 0 10rem;
}

.modalBox {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1000;
}

.cardList {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
max-width: 1200px;
}
17 changes: 1 addition & 16 deletions src/app/shopinfo/page.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
'use client';

import { useContext, useEffect } from 'react';
import Cookies from 'js-cookie';
import BASE_URL from '@/constants/BASEURL';
import { ShopDataContext } from '@/context/ShopDataContext';
import ShopInformation from './ShopInformation';
import ShopRegistration from './ShopRegistration';

export default function ShopInfo() {
const { shopData, updateShopData } = useContext(ShopDataContext);
const shopId = Cookies.get('shopId');

useEffect(() => {
if (shopId) {
const fetchData = async () => {
const result = await fetch(`${BASE_URL}/shops/${shopId}`);
const data = await result.json();
updateShopData(data.item);
};
fetchData();
}
}, [shopId]);

return shopData.id ? <ShopInformation /> : <ShopRegistration />;
return shopId ? <ShopInformation /> : <ShopRegistration />;
}
32 changes: 32 additions & 0 deletions src/components/common/Header/SearchBox.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,35 @@
width: 100%;
}
}

.itemBox {
position: absolute;
display: flex;
flex-direction: column;
top: 5rem;
left: 0;
z-index: 1;
width: 100%;
overflow: hidden;
background: $white;
border: 2px solid $red-200;

@include rounded-lg;
}

.item {
padding: 0.6rem 1.5rem;
font-size: 1.6rem;
border: none;
background: none;
cursor: pointer;
border: 1px solid $red-600;

span {
@include font-bold;
}

&:hover {
background: $red-600;
}
}
Loading