diff --git a/src/ts/page/admin/dashboard.ts b/src/ts/page/admin/dashboard.ts index 4b03dca..2dbbe89 100644 --- a/src/ts/page/admin/dashboard.ts +++ b/src/ts/page/admin/dashboard.ts @@ -92,7 +92,7 @@ const setDashBoardChartAmount = ( const thisWeek: number[] = []; for (let i = 0; i < 7; i++) { - thisWeek.unshift(Number(getDate().today) - i); + thisWeek.unshift(Number(getDate(i).date)); } const amountOfthisWeek: number[] = []; diff --git a/src/ts/page/admin/order.ts b/src/ts/page/admin/order.ts index d141a52..3bfb1f3 100644 --- a/src/ts/page/admin/order.ts +++ b/src/ts/page/admin/order.ts @@ -52,13 +52,18 @@ export const handleOrderPage = async (): Promise => { '.order-container__search-container--input input', ); + const searchedOrderBtn = $( + '.order-container__search-container--input input', + ); + const searchOrderHandler = (): void => { const filteredOrder = orders.filter((order) => - order.user.displayName.includes(searchedOrderInput.value), + order.user.displayName + .trim() + .toLowerCase() + .includes(searchedOrderInput.value), ); - orders = filteredOrder; - orderList.innerHTML = ``; renderPageBtn(orderPageBtn, filteredOrder, 1, itemsPerPage, 1); newOrders = getOrderCurrentPage(filteredOrder, 1, itemsPerPage); @@ -67,19 +72,16 @@ export const handleOrderPage = async (): Promise => { /** 거래내역 검색(enter) 이벤트 리스너 */ searchedOrderInput.addEventListener('keydown', (e) => { - if (e.key === 'Enter' && !e.isComposing) { + if (e.key === 'Enter') { searchOrderHandler(); } }); - searchedOrderInput.addEventListener('input', async () => { - searchedOrderInput.value === '' ? (orders = await getAllOrder()) : orders; + /** 거래내역 검색(버튼 클릭) 이벤트 리스너 */ + searchedOrderBtn.addEventListener('click', async () => { searchOrderHandler(); }); - /** 거래내역 검색(버튼 클릭) 이벤트 리스너 */ - // searchedOrderBtn.addEventListener('click', searchOrderHandler); - /** 버튼 클릭 페이지 이동 이벤트 리스너 */ orderPageBtn.addEventListener('click', (e: MouseEvent) => { if ((e.target as HTMLButtonElement).classList.contains('btn-page')) return; diff --git a/src/ts/page/admin/product.ts b/src/ts/page/admin/product.ts index e829bc0..4049c57 100644 --- a/src/ts/page/admin/product.ts +++ b/src/ts/page/admin/product.ts @@ -40,26 +40,29 @@ let newProducts = getProductCurrentPage( /** 상품관리 페이지 핸들러 */ export const handleProductPage = async (): Promise => { - const productList = $('.product-container__list') as HTMLUListElement; - const checkProductAll = $( + const productList = $('.product-container__list'); + const checkProductAll = $( '.product-container__title input', - ) as HTMLInputElement; - const productPageBtn = $('.product-container__btn-page') as HTMLButtonElement; + ); + const productPageBtn = $('.product-container__btn-page'); products = await getAllProducts(); setUpUI(productPageBtn, productList); - const searchedProductInput = $( + const searchedProductInput = $( '.product-container__search-container--input input', - ) as HTMLInputElement; + ); + + const searchedProductBtn = $( + '.product-container__search-container--input input', + ); const searchProductHandler = (): void => { const filteredProduct = products.filter((product) => - product.title.toLowerCase().includes(searchedProductInput.value), + product.title.trim().toLowerCase().includes(searchedProductInput.value), ); - products = filteredProduct; productList.innerHTML = ``; renderPageBtn(productPageBtn, filteredProduct, 1, itemsPerPage, 1); newProducts = getProductCurrentPage(filteredProduct, 1, itemsPerPage); @@ -68,21 +71,16 @@ export const handleProductPage = async (): Promise => { /** 상품 검색(enter) 이벤트 리스너 */ searchedProductInput.addEventListener('keydown', (e: KeyboardEvent) => { - if (e.key === 'Enter' && !e.isComposing) { + if (e.key === 'Enter') { searchProductHandler(); } }); - searchedProductInput.addEventListener('input', async () => { - searchedProductInput.value === '' - ? (products = await getAllProducts()) - : products; + /** 상품 검색 이벤트 리스너 */ + searchedProductBtn.addEventListener('click', async () => { searchProductHandler(); }); - /** 상품 검색(버튼 클릭) 이벤트 리스너 */ - // searchedProductBtn.addEventListener('click', searchProductHandler); - /** 페이지 버튼 클릭 이벤트 리스너 */ productPageBtn.addEventListener('click', (e: MouseEvent) => { if ( @@ -168,14 +166,6 @@ export const handleProductPage = async (): Promise => { } if (confirm('선택한 상품을 삭제하시겠습니까? ')) { - // async function deleteProductPromise(newProductsEl) { - // const productsMap = newProductsEl.map(async (newProductEl) => { - // return await deleteProduct(newProductEl.dataset.id); - // }); - // return productsMap; - // } - - // await deleteProductPromise(newProductsEl); await Promise.all( newProductsEl.map( async (newProductEl: any) => diff --git a/src/ts/utils/date.ts b/src/ts/utils/date.ts index 28a2f3b..8a5ff86 100644 --- a/src/ts/utils/date.ts +++ b/src/ts/utils/date.ts @@ -1,17 +1,32 @@ interface getDateInterface { - date: Date; + year: string; month: string; - today: string; + date: string; } -export const getDate = (): getDateInterface => { +export const getDate = (prevDateNum: number = 0): getDateInterface => { const today = new Date(); const dateObj: getDateInterface = { - date: today, + year: String(today.getFullYear()), month: String(today.getMonth() + 1).padStart(2, '0'), - today: String(today.getDate()).padStart(2, '0'), + date: String(today.getDate()).padStart(2, '0'), }; - return dateObj; + if (!prevDateNum) return dateObj; + else { + const prevDate = new Date( + Number(dateObj.year), + Number(dateObj.month) - 1, + Number(dateObj.date) - prevDateNum, + ); + + const prevDateObj: getDateInterface = { + year: String(prevDate.getFullYear()), + month: String(prevDate.getMonth() + 1).padStart(2, '0'), + date: String(prevDate.getDate()).padStart(2, '0'), + }; + + return prevDateObj; + } };