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

fix: 修正賣家訂單管理功能與買家訂單權限 #83

Merged
merged 4 commits into from
Jan 8, 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
30 changes: 18 additions & 12 deletions src/app/chat/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

/* 取得聯絡人資訊 */
Expand All @@ -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]);
}
});
Expand Down Expand Up @@ -123,7 +128,7 @@ const WebSocketTest = () => {
.filter((message) => message !== null); // 過濾掉可能的空值
setMessages(messageObjects);

console.log(previousMessagesData);
// console.log(previousMessagesData);
// 設置先前的聊天訊息到狀態中
// setPreviousMessages(previousMessagesData);
} catch (error) {
Expand Down Expand Up @@ -188,7 +193,7 @@ const WebSocketTest = () => {
};
}
});
console.log(messageObjects);
// console.log(messageObjects);
setMessages(messageObjects);
// messageObjects.forEach((msgObj) => {
// setMessages((prevMessages) => [...prevMessages, msgObj]);
Expand Down Expand Up @@ -308,6 +313,7 @@ const WebSocketTest = () => {
</MessageList>
<MessageInput
value={userMessage}
disabled={isInputDisabled}
onChange={handleInputChange}
placeholder="請在此輸入訊息"
onSend={handleSendMessage}
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
20 changes: 5 additions & 15 deletions src/app/my-order/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand Down Expand Up @@ -351,7 +351,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand Down Expand Up @@ -396,7 +396,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand Down Expand Up @@ -427,7 +427,6 @@ export default function Orders() {
<TableCell>付款金額</TableCell>
<TableCell>購買數量</TableCell>
<TableCell>訂單狀態</TableCell>
<TableCell>更改訂單狀態</TableCell>
<TableCell>聯絡賣家</TableCell>
</TableRow>
</TableHead>
Expand All @@ -443,7 +442,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand All @@ -452,15 +451,6 @@ export default function Orders() {
))}
</TableCell>
<TableCell>{getStatusText(order.status)}</TableCell>
<TableCell>
<Button
variant="contained"
color="primary"
onClick={() => handleOrderDoneClick(order.orderid)}
>
完成訂單
</Button>
</TableCell>
<TableCell>
<IconButton onClick={() => handleButtonClick(order)}>
<QuestionAnswerIcon color="secondary"/>
Expand Down Expand Up @@ -500,7 +490,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand Down
48 changes: 6 additions & 42 deletions src/app/order/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Paper
sx={{ p: 2, display: "flex", flexDirection: "column" }}
Expand Down Expand Up @@ -324,7 +299,7 @@ export default function Orders() {
<TableCell>訂單狀態</TableCell>
<TableCell>管理訂單狀態</TableCell>
<TableCell>更改訂單狀態</TableCell>
<TableCell>聯絡賣家</TableCell>
{/* <TableCell>聯絡賣家</TableCell> */}
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -339,7 +314,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand Down Expand Up @@ -372,11 +347,6 @@ export default function Orders() {
執行
</Button>
</TableCell>
<TableCell>
<IconButton onClick={() => handleButtonClick(order)}>
<QuestionAnswerIcon color="secondary" />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
Expand Down Expand Up @@ -411,7 +381,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand Down Expand Up @@ -454,7 +424,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand Down Expand Up @@ -484,7 +454,6 @@ export default function Orders() {
<TableCell>購買數量</TableCell>
<TableCell>訂單狀態</TableCell>
<TableCell>更改訂單狀態</TableCell>
<TableCell>聯絡賣家</TableCell>
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -499,7 +468,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand All @@ -517,11 +486,6 @@ export default function Orders() {
完成訂單
</Button>
</TableCell>
<TableCell>
<IconButton onClick={() => handleButtonClick(order)}>
<QuestionAnswerIcon color="secondary" />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
Expand Down Expand Up @@ -556,7 +520,7 @@ export default function Orders() {
</TableCell>
<TableCell>
{order.productAddAmountList.map((productItem, index) => (
<div key={index}>{productItem.product.currentPrice}</div>
<div key={index}>{productItem.product.currentPrice * productItem.amount}</div>
))}
</TableCell>
<TableCell>
Expand Down
Loading