diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 241b9ea..37656a6 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -72,7 +72,7 @@ const mockTagData = [ { value: 'ingr-5', label: '# 재료 5' }, ]; -const mockRecipeData: RecipeProps[] = Array(14).fill({ +export const mockRecipeData: RecipeProps[] = Array(14).fill({ author: '해피밀', contents: `소스 : 스리라차 소스, 요거트 소스 반죽 : 밀가루, 계란 diff --git a/src/pages/inventory/components/IngrInputBox.tsx b/src/pages/inventory/components/IngrInputBox.tsx index 8380c06..cdbbfec 100644 --- a/src/pages/inventory/components/IngrInputBox.tsx +++ b/src/pages/inventory/components/IngrInputBox.tsx @@ -62,24 +62,24 @@ function IngrInputBox({ ...props }: IngrInputBoxProps) { moment.locale('ko'); - const [registerDate, setRegisterDate] = useState( + const [registrationDate, setRegistrationDate] = useState( moment().locale('ko'), ); - const [bestBefore, setBestBefore] = useState(null); + const [expirationDate, setExpirationDate] = useState(null); const [inputData, setInputData] = useState( item ? { name: item.name, - number: item.number, - registerDate: item.registerDate, - bestBefore: item.bestBefore, + quantity: item.quantity, + registrationDate: item.registrationDate, + expirationDate: item.expirationDate, } : { name: '', - number: '', - registerDate: registerDate, - bestBefore: bestBefore, + quantity: '', + registrationDate: registrationDate, + expirationDate: expirationDate, }, ); const [isComposing, composeProps] = useComposing(); @@ -91,13 +91,13 @@ function IngrInputBox({ if (e.code === 'Enter' && inputData.name) { handleDataChange && handleDataChange(inputData); - setRegisterDate(moment().locale('ko')); - setBestBefore(null); + setRegistrationDate(moment().locale('ko')); + setExpirationDate(null); setInputData({ name: '', - number: '', - registerDate: registerDate, - bestBefore: bestBefore, + quantity: '', + registrationDate: registrationDate, + expirationDate: expirationDate, }); inputRef.current?.focus(); } @@ -151,9 +151,9 @@ function IngrInputBox({ /> { - setInputData({ ...inputData, number: e.target.value }); + setInputData({ ...inputData, quantity: e.target.value }); }} onKeyDown={handleKeyDown} css={styles.input.default} @@ -161,18 +161,18 @@ function IngrInputBox({ {...composeProps} /> { - setInputData({ ...inputData, registerDate: date }); + setInputData({ ...inputData, registrationDate: date }); }} targetRef={inputRef} > 등록일자 설정 { - setInputData({ ...inputData, bestBefore: date }); + setInputData({ ...inputData, expirationDate: date }); }} placeholder="유통기한 날짜를 선택해주세요." targetRef={inputRef} @@ -186,14 +186,14 @@ function IngrInputBox({ {inputData.name} - {inputData.number} + {inputData.quantity} - {inputData.registerDate.format('YYYY/MM/DD').toString()} + {inputData.registrationDate.format('YYYY/MM/DD').toString()} - {inputData.bestBefore - ? inputData.bestBefore.format('YYYY/MM/DD').toString() + {inputData.expirationDate + ? inputData.expirationDate.format('YYYY/MM/DD').toString() : ''} diff --git a/src/pages/inventory/components/ShortExpirationItem.tsx b/src/pages/inventory/components/ShortExpirationItem.tsx new file mode 100644 index 0000000..7f45d1d --- /dev/null +++ b/src/pages/inventory/components/ShortExpirationItem.tsx @@ -0,0 +1,50 @@ +import { ReactComponent as IconCaution } from '@/assets/icon-caution.svg'; +import DesignSystem from '@/utils/designSystem'; +import { Group, Stack, Typography } from '@base'; +import { css } from '@emotion/react'; +import moment from 'moment'; +import { IngredientDataType } from '..'; +interface ShortExpirationItemProps { + item: IngredientDataType; +} +const styles = { + infoBox: css({ + backgroundColor: DesignSystem.Color.background.gray, + border: '1px solid', + borderColor: DesignSystem.Color.background.black, + marginLeft: -1, + padding: '17.5px 119px 32px 18.6px', + }), +}; +function ShortExpirationItem({ item }: ShortExpirationItemProps) { + return ( + + + {item.name} + {item.expirationDate?.isBefore(moment()) && ( + + )} + + + 수량 : {item.quantity} + + 등록 일자 : {item.registrationDate?.format('YYYY/MM/DD').toString()} + + + 유통기한 : {item.expirationDate?.format('YYYY/MM/DD').toString()} + + + + ); +} + +export default ShortExpirationItem; diff --git a/src/pages/inventory/index.tsx b/src/pages/inventory/index.tsx index 13bd23d..32fa677 100644 --- a/src/pages/inventory/index.tsx +++ b/src/pages/inventory/index.tsx @@ -4,10 +4,14 @@ import { ReactComponent as IconList } from '@/assets/icon-list.svg'; import DesignSystem from '@/utils/designSystem'; import globalStyles from '@/utils/styles'; import { Group, Stack, Typography } from '@base'; +import Pagenumber from '@copmonents/Pagenumber'; +import Recipe from '@copmonents/Recipe'; import { css } from '@emotion/react'; import moment, { Moment } from 'moment'; import { useEffect, useRef, useState } from 'react'; +import { mockRecipeData } from '../home'; import IngrInputBox from './components/IngrInputBox'; +import ShortExpirationItem from './components/ShortExpirationItem'; const styles = { wrapper: css({}), inventory: { @@ -54,15 +58,62 @@ const styles = { export interface IngredientDataType { name: string; - number: string; - registerDate: Moment; - bestBefore: Moment | null; + quantity: string; + registrationDate: Moment; + expirationDate: Moment | null; } function Inventory() { const [data, setData] = useState([]); const [isEditing, setIsEditing] = useState(false); const [submit, setSubmit] = useState(false); + const [isOverflowed, setIsOverflowed] = useState(false); + const [currentPage, setCurrentPage] = useState(1); + const checkRef = useRef(null); + + const mockIngredientData: IngredientDataType[][] = [ + [ + { + name: '김치', + quantity: '3개', + registrationDate: moment('2023-02-05'), + expirationDate: moment('2024-02-05'), + }, + { + name: '소고기', + quantity: '300g', + registrationDate: moment('2023-02-05'), + expirationDate: moment('2023-02-05'), + }, + { + name: '양파', + quantity: '5개', + registrationDate: moment('2023-02-05'), + expirationDate: moment('2023-02-05'), + }, + { + name: '양파', + quantity: '5개', + registrationDate: moment('2023-02-05'), + expirationDate: moment('2023-02-05'), + }, + ], + [ + { + name: '양파', + quantity: '5개', + registrationDate: moment('2023-02-05'), + expirationDate: moment('2023-02-05'), + }, + { + name: '양파', + quantity: '5개', + registrationDate: moment('2023-02-05'), + expirationDate: moment('2023-02-05'), + }, + ], + ]; + const handleDataChange = (inputData: IngredientDataType) => { setData([{ ...inputData }, ...data]); }; @@ -72,9 +123,6 @@ function Inventory() { const handleDelete = (targetIdx: number) => { setData(data.filter((_, idx) => idx !== targetIdx)); }; - const checkRef = useRef(null); - - const [isOverflowed, setIsOverflowed] = useState(false); useEffect(() => { setIsOverflowed( @@ -83,7 +131,7 @@ function Inventory() { ); }); return ( - + @@ -217,7 +265,7 @@ function Inventory() { handleRemove={() => { handleDelete(idx); }} - key={`${idx}-${item.name}-${item.registerDate}`} + key={`${idx}-${item.name}-${item.registrationDate}`} /> ); })} @@ -229,6 +277,41 @@ function Inventory() { + + + 유통기한이 얼마 남지 않은 재료 + + + {mockIngredientData[currentPage - 1].map((item, idx) => { + return ; + })} + + + { + setCurrentPage(page); + }} + /> + + + 재료 기반 추천 레시피 + +
+ {mockRecipeData.map((props, index) => ( + + ))} +
+
); }