From 752e3c9de9115f8afd58f6df611b76a506479fe1 Mon Sep 17 00:00:00 2001 From: anthony Date: Fri, 5 Jan 2024 12:50:25 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E8=B3=A3=E5=AE=B6?= =?UTF-8?q?=E8=A8=82=E5=96=AE=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=E8=88=87?= =?UTF-8?q?=E8=B2=B7=E5=AE=B6=E8=A8=82=E5=96=AE=E6=AC=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/my-order/page.js | 10 ---------- src/app/order/page.js | 38 +------------------------------------- 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/src/app/my-order/page.js b/src/app/my-order/page.js index 72e08ba..75a35dd 100644 --- a/src/app/my-order/page.js +++ b/src/app/my-order/page.js @@ -427,7 +427,6 @@ export default function Orders() { 付款金額 購買數量 訂單狀態 - 更改訂單狀態 聯絡賣家 @@ -452,15 +451,6 @@ export default function Orders() { ))} {getStatusText(order.status)} - - - handleButtonClick(order)}> diff --git a/src/app/order/page.js b/src/app/order/page.js index fe84e42..16e5b2f 100644 --- a/src/app/order/page.js +++ b/src/app/order/page.js @@ -265,31 +265,6 @@ export default function Orders() { fetchOrder(); }, []); - const handleButtonClick = (order) => { - // 從本地端存儲讀取已有的使用者資訊陣列,如果沒有就創建一個新陣列 - localStorage.removeItem("usersReceiver"); - const users = JSON.parse( - localStorage.getItem("usersReceiver") ?? "[]" - ); - const sellerIDToAdd = (order.buyerid); - var sellerNameToAdd = ""; - {order.productAddAmountList.map((productItem) => ( - sellerNameToAdd = productItem.product.sellerName - ))} - - const isSellerIDExists = users.some( - (user) => user.id === sellerIDToAdd - ); - - if (!isSellerIDExists) { - // 將新的 sellerID 添加到 users 陣列 - users.push({ id: sellerIDToAdd, name: sellerNameToAdd }); - // 存回 localStorage - localStorage.setItem("usersReceiver", JSON.stringify(users)); - } - window.location.href = '../chat' - }; - return ( 訂單狀態 管理訂單狀態 更改訂單狀態 - 聯絡賣家 + {/* 聯絡賣家 */} @@ -372,11 +347,6 @@ export default function Orders() { 執行 - - handleButtonClick(order)}> - - - ))} @@ -484,7 +454,6 @@ export default function Orders() { 購買數量 訂單狀態 更改訂單狀態 - 聯絡賣家 @@ -517,11 +486,6 @@ export default function Orders() { 完成訂單 - - handleButtonClick(order)}> - - - ))} From 54ea9c610fe3eada128c2a23b5fa314c2e60b4e5 Mon Sep 17 00:00:00 2001 From: anthony Date: Fri, 5 Jan 2024 14:30:36 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E8=81=AF=E7=B5=A1?= =?UTF-8?q?=E4=BA=BA=E9=87=8D=E8=A4=87=E5=8A=A0=E5=85=A5=EF=BC=8C=E5=B0=9A?= =?UTF-8?q?=E6=9C=AA=E7=99=BB=E5=85=A5=E6=99=82=E6=87=89=E7=84=A1=E6=B3=95?= =?UTF-8?q?=E9=80=B2=E5=85=A5=E8=81=8A=E5=A4=A9=E5=AE=A4=E9=A0=81=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/chat/page.js | 30 ++++++++++++++--------- src/components/MediaCard.jsx | 47 ++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/app/chat/page.js b/src/app/chat/page.js index ce8ee56..47fd7e4 100644 --- a/src/app/chat/page.js +++ b/src/app/chat/page.js @@ -21,24 +21,29 @@ import "@chatscope/chat-ui-kit-styles/dist/default/styles.min.css"; const token = Cookies.get("token"); -// const users = localStorage.getItem("usersReceiver"); -// const users = [ -// { id: "1", name: "admin" }, -// { id: "2", name: "shit" }, -// ]; - const WebSocketTest = () => { // const [user, setUser] = useState(null); const [userMessage, setUserMessage] = useState(""); /* 使用者輸入欄的訊息 */ const [messages, setMessages] = useState([]); const [client, setClient] = useState(null); - const [selectedUser, setSelectedUser] = useState(null); + const [isInputDisabled, setIsInputDisabled] = useState(true); + const handleUserClick = (userId) => { - console.log(userId); + // console.log(userId); setSelectedUser(userId); setMessages([]); fetchPreviousMessages(userId); + handleCondition(); + setIsInputDisabled(false); + }; + + const handleCondition = () => { + if (selectedUser !== null) { + setIsInputDisabled(false); + } else { + setIsInputDisabled(true); + } }; /* 取得聯絡人資訊 */ @@ -59,8 +64,8 @@ const WebSocketTest = () => { const parsedContacts = JSON.parse(storedContacts); // 檢查每個 storedContacts 是否存在於 users 中,若不存在則加入 parsedContacts.forEach(contact => { - if (!users.some(user => user.id === contact.id)) { - console.log("test" + parsedContacts) + if (!contactsArray.some(user => user.id == contact.id)) { + console.log(`Contact ${contact.id} not found in contactsArray`); setContacts(prevContacts => [...prevContacts, contact]); } }); @@ -123,7 +128,7 @@ const WebSocketTest = () => { .filter((message) => message !== null); // 過濾掉可能的空值 setMessages(messageObjects); - console.log(previousMessagesData); + // console.log(previousMessagesData); // 設置先前的聊天訊息到狀態中 // setPreviousMessages(previousMessagesData); } catch (error) { @@ -188,7 +193,7 @@ const WebSocketTest = () => { }; } }); - console.log(messageObjects); + // console.log(messageObjects); setMessages(messageObjects); // messageObjects.forEach((msgObj) => { // setMessages((prevMessages) => [...prevMessages, msgObj]); @@ -308,6 +313,7 @@ const WebSocketTest = () => { { - // 從本地端存儲讀取已有的使用者資訊陣列,如果沒有就創建一個新陣列 - localStorage.removeItem("usersReceiver"); - const users = JSON.parse( - localStorage.getItem("usersReceiver") ?? "[]" - ); - const sellerIDToAdd = (commodity.sellerID); - const sellerNameToAdd = (commodity.sellerName); - - const isSellerIDExists = users.some( - (user) => user.id === sellerIDToAdd - ); - - if (!isSellerIDExists) { - // 將新的 sellerID 添加到 users 陣列 - users.push({ id: sellerIDToAdd, name: sellerNameToAdd }); - // 存回 localStorage - localStorage.setItem("usersReceiver", JSON.stringify(users)); + if(user){ + // 從本地端存儲讀取已有的使用者資訊陣列,如果沒有就創建一個新陣列 + localStorage.removeItem("usersReceiver"); + const users = JSON.parse( + localStorage.getItem("usersReceiver") ?? "[]" + ); + if(commodity.sellerID != user.id){ + const sellerIDToAdd = (commodity.sellerID); + const sellerNameToAdd = (commodity.sellerName); + + const isSellerIDExists = users.some( + (user) => user.id === sellerIDToAdd + ); + + if (!isSellerIDExists) { + // 將新的 sellerID 添加到 users 陣列 + users.push({ id: sellerIDToAdd, name: sellerNameToAdd }); + // 存回 localStorage + localStorage.setItem("usersReceiver", JSON.stringify(users)); + } + window.location.href = '../chat' + } + else{ + setError("此商品為您的商品"); + setOpenSnackbarErrror(true); + } + } + else{ + window.location.href = "/sign-in"; } - window.location.href = '../chat' }; React.useEffect(() => { From 25e2852cc5c5fc26ca46bdd8633ae1d3c526d6b5 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 8 Jan 2024 20:18:39 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=94=B6?= =?UTF-8?q?=E5=85=A5=E5=A0=B1=E8=A1=A8=E5=8A=9F=E8=83=BD=E3=80=81=E6=94=B6?= =?UTF-8?q?=E5=85=A5=E7=B5=B1=E8=A8=88=E5=8A=9F=E8=83=BD=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E8=A8=82=E5=96=AE=E9=A1=AF=E7=A4=BA=E5=83=B9=E6=A0=BC?= =?UTF-8?q?=E9=8C=AF=E8=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/layout.tsx | 2 +- src/app/my-order/page.js | 10 +- src/app/order/page.js | 10 +- src/components/Chart.js | 293 +++++++------------------------------ src/components/Deposits.js | 62 ++++++-- 5 files changed, 107 insertions(+), 270 deletions(-) diff --git a/src/app/layout.tsx b/src/app/layout.tsx index d22cc7a..d186b56 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -110,7 +110,7 @@ export default function RootLayout({ ]; const SELLER_CENTER_LINKS = [ - //{ text: "賣家中心", href: user ? "/dashbord" : "/sign-in", icon: StorefrontIcon }, + { text: "賣家中心", href: user ? "/dashbord" : "/sign-in", icon: StorefrontIcon }, { text: "商品管理", href: user ? "/seller-product" : "/sign-in", icon: SellIcon }, { text: "訂單管理", href: user ? "/order" : "/sign-in", icon: ContentPasteIcon }, { text: "上架商品", href: user ? "/add-product" : "/sign-in", icon: AddIcon }, diff --git a/src/app/my-order/page.js b/src/app/my-order/page.js index 75a35dd..be8fb88 100644 --- a/src/app/my-order/page.js +++ b/src/app/my-order/page.js @@ -282,7 +282,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
@@ -351,7 +351,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
@@ -396,7 +396,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
@@ -442,7 +442,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
@@ -490,7 +490,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
diff --git a/src/app/order/page.js b/src/app/order/page.js index 16e5b2f..7a4581b 100644 --- a/src/app/order/page.js +++ b/src/app/order/page.js @@ -314,7 +314,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
@@ -381,7 +381,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
@@ -424,7 +424,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
@@ -468,7 +468,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
@@ -520,7 +520,7 @@ export default function Orders() { {order.productAddAmountList.map((productItem, index) => ( -
{productItem.product.currentPrice}
+
{productItem.product.currentPrice * productItem.amount}
))}
diff --git a/src/components/Chart.js b/src/components/Chart.js index cc10ad3..b92a414 100644 --- a/src/components/Chart.js +++ b/src/components/Chart.js @@ -1,190 +1,9 @@ "use client"; -// import * as React from "react"; -// import { useTheme } from "@mui/material/styles"; +import React, { useState, useEffect } from "react"; import Paper from "@mui/material/Paper"; -// import { -// LineChart, -// Line, -// XAxis, -// YAxis, -// Label, -// ResponsiveContainer, -// } from "recharts"; import Title from "./Title"; - -// // Generate Sales Data -// function createData(time, amount) { -// return { time, amount }; -// } - -// const data = [ -// createData("12/04", 1000), -// createData("12/05", 300), -// createData("12/06", 2600), -// createData("12/07", 800), -// createData("12/08", 1500), -// createData("12/09", 200), -// ]; - -// export default function Chart() { -// const theme = useTheme(); - -// return ( -// -// -// 本週收入 -// -// -// -// -// -// -// -// -// -// -// -// ); -// } - -// import React, { PureComponent } from "react"; -// import { -// LineChart, -// Line, -// XAxis, -// YAxis, -// CartesianGrid, -// Tooltip, -// Legend, -// ResponsiveContainer, -// } from "recharts"; - -// const data = [ -// { -// name: "Page A", -// uv: 4000, -// pv: 2400, -// amt: 2400, -// }, -// { -// name: "Page B", -// uv: 3000, -// pv: 1398, -// amt: 2210, -// }, -// { -// name: "Page C", -// uv: 2000, -// pv: 9800, -// amt: 2290, -// }, -// { -// name: "Page D", -// uv: 2780, -// pv: 3908, -// amt: 2000, -// }, -// { -// name: "Page E", -// uv: 1890, -// pv: 4800, -// amt: 2181, -// }, -// { -// name: "Page F", -// uv: 2390, -// pv: 3800, -// amt: 2500, -// }, -// { -// name: "Page G", -// uv: 3490, -// pv: 4300, -// amt: 2100, -// }, -// ]; - -// export default function Example() { -// return ( -// -// -// -// -// -// -// -// -// -// {/* */} -// -// -// -// -// -// ); -// } - -import React from "react"; +import axios from "axios"; +import Cookies from "js-cookie"; import { BarChart, Bar, @@ -197,68 +16,60 @@ import { ResponsiveContainer, } from "recharts"; -const data = [ - { - name: "12/04", - uv: 4000, - 收入: 240, - amt: 2400, - }, - { - name: "12/05", - uv: 3000, - 收入: 139, - amt: 2210, - }, - { - name: "12/06", - uv: 2000, - 收入: 980, - amt: 2290, - }, - { - name: "12/07", - uv: 2780, - 收入: 398, - amt: 2000, - }, - { - name: "12/08", - uv: 1890, - 收入: 480, - amt: 2181, - }, - { - name: "12/09", - uv: 2390, - 收入: 380, - amt: 2500, - }, - { - name: "12/10", - uv: 3490, - 收入: 430, - amt: 2100, - }, -]; +const INCOMEAPI = "api/v1/order/check/income" +const token = Cookies.get("token"); + +async function fetchIncome() { + const response = await axios.get(INCOMEAPI, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + return response.data; +} + export default function Chart() { + const [incomesData, setIncomesData] = useState([]); + + useEffect(() => { + async function fetchData() { + try { + const incomeData = await fetchIncome(); + setIncomesData(incomeData); + // console.log(incomeData) + } catch (error) { + console.error("獲取收入資料錯誤:", error); + } + } + fetchData(); + }, []); + + const convertedData = []; + // useEffect(() => { + const today = new Date(); + for (let i = 7; i >= 0; i--) { + const date = new Date(today); + date.setDate(date.getDate() - i); + const addZero = (num) => (num < 10 ? `0${num}` : num); + const formattedDate = `${addZero(date.getMonth() + 1)}/${addZero(date.getDate())}`; + const income = incomesData[i]; + convertedData.push({ + date: formattedDate, + 收入: income + }); + } + // console.log(convertedData); + // }, [incomesData]); + return ( - // <strong>本週收入</strong> - + @@ -276,14 +87,8 @@ export default function Chart() { fill="#8884d8" activeBar={} /> - {/* } - /> */} - /* */ ); } \ No newline at end of file diff --git a/src/components/Deposits.js b/src/components/Deposits.js index 34b8301..b7302ad 100644 --- a/src/components/Deposits.js +++ b/src/components/Deposits.js @@ -1,28 +1,60 @@ -"use client" -import * as React from 'react'; -import Link from '@mui/material/Link'; -import Typography from '@mui/material/Typography'; -import Title from './Title'; +"use client"; +import React, { useState, useEffect } from "react"; +import Link from "@mui/material/Link"; +import Typography from "@mui/material/Typography"; +import Title from "./Title"; +import axios from "axios"; +import Cookies from "js-cookie"; -function preventDefault(event) { - event.preventDefault(); +const INCOMEAPI = "api/v1/order/check/income"; +const token = Cookies.get("token"); + +async function fetchIncome() { + const response = await axios.get(INCOMEAPI, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + return response.data; } export default function Deposits() { + const [incomesData, setIncomesData] = useState([]); + const total = incomesData.reduce((accumulator, currentValue) => accumulator + currentValue, 0); + const formattedTotal = "NT$" + total.toLocaleString("zh-TW"); + useEffect(() => { + async function fetchData() { + try { + const incomeData = await fetchIncome(); + setIncomesData(incomeData); + console.log(incomeData) + } catch (error) { + console.error("獲取收入資料錯誤:", error); + } + } + fetchData(); + }, []); + + const today = new Date(); // 獲取當前日期 + const oneWeekAgo = new Date(today); + oneWeekAgo.setDate(oneWeekAgo.getDate() - 8); + const year = oneWeekAgo.getFullYear(); // 取得年份 + const month = oneWeekAgo.getMonth() + 1; // 取得月份 + const day = oneWeekAgo.getDate(); // 取得日期 + const addZero = (num) => (num < 10 ? `0${num}` : num); + const formattedDate = `${year}-${addZero(month)}-${addZero(day)}`; + return ( - <strong>最近的總收入</strong> + + <strong>最近的總收入</strong> + - $3,024.00 + {formattedTotal} - 截止日期 2023/11/28 + 截止日期 {formattedDate} -
- - 查看平均收入 - -
); } \ No newline at end of file From ebc36a72f79ede7dec715eee437ac180cfeda815 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 8 Jan 2024 20:23:12 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E7=B5=B1=E8=A8=88?= =?UTF-8?q?=E5=9C=96=E8=A1=A8=E9=A1=AF=E7=A4=BA=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Deposits.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Deposits.js b/src/components/Deposits.js index b7302ad..72bd63e 100644 --- a/src/components/Deposits.js +++ b/src/components/Deposits.js @@ -53,7 +53,7 @@ export default function Deposits() { {formattedTotal} - 截止日期 {formattedDate} + 從 {formattedDate} 至今 );