From c247cb7f6d36e68a89e890286a8402fb2f826151 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 20 Feb 2024 11:01:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20Zustand=20=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/OrderStore.js | 21 +++++++ .../Components/CustomerProfile.jsx | 56 ++++++++----------- 2 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 src/stores/OrderStore.js diff --git a/src/stores/OrderStore.js b/src/stores/OrderStore.js new file mode 100644 index 0000000..6240d48 --- /dev/null +++ b/src/stores/OrderStore.js @@ -0,0 +1,21 @@ +import { create } from 'zustand' +import { devtools } from 'zustand/middleware' +import { fetchJSON, postJSON } from '@/utils/request' + +const API_HOST = 'https://p9axztuwd7x8a7.mycht.cn/whatsapp_callback'; + +const useOrderStore = create((set, get) => ({ + + orderDetail: { + order_no: '' + }, + + fetchOrderDetail: async (colisn) => { + const json = await fetchJSON(`${API_HOST}/getorderinfo`, { colisn }) + if (json.errcode === 0 && json.result.length > 0) { + set(state => ({ orderDetail: json.result[0] })) + } + } +})) + +export default useOrderStore \ No newline at end of file diff --git a/src/views/Conversations/Components/CustomerProfile.jsx b/src/views/Conversations/Components/CustomerProfile.jsx index 689b64c..193ee68 100644 --- a/src/views/Conversations/Components/CustomerProfile.jsx +++ b/src/views/Conversations/Components/CustomerProfile.jsx @@ -1,42 +1,32 @@ -import { Card, Flex, Select, Typography, Radio, Button, Table } from 'antd'; -import { useAuthContext } from '@/stores/AuthContext.js'; -// import { useConversationState } from '@/stores/ConversationContext'; +import { useEffect } from 'react' import { useLocation, useParams } from 'react-router-dom' -import { UserOutlined, EditOutlined, EllipsisOutlined, SmileOutlined, SyncOutlined, PhoneOutlined, MailOutlined, WhatsAppOutlined, SmileTwoTone } from '@ant-design/icons'; +import { Card, Flex, Select, Typography, Radio, Button, Table } from 'antd' +import { useAuthContext } from '@/stores/AuthContext.js' +import { UserOutlined, EditOutlined, EllipsisOutlined, SmileOutlined, SyncOutlined, PhoneOutlined, MailOutlined, WhatsAppOutlined, SmileTwoTone } from '@ant-design/icons' -import CreatePayment from './CreatePayment'; -import QuotesHistory from './QuotesHistory'; - -const orderTags = [ - { value: 'potential', label: '潜力' }, - { value: 'important', label: '重点' }, - { label: '休眠', value: 'snooze' }, -]; - -const orderStatus = [ - { value: 'pending', label: '报价中' }, - // { value: 'in-progress', label: '处理中' }, - { value: 'lost', label: '丢失' }, - { value: 'later', label: '以后联系' }, -]; - -const { Meta } = Card; +import CreatePayment from './CreatePayment' +import QuotesHistory from './QuotesHistory' +import useOrderStore from '@/stores/OrderStore' const CustomerProfile = (() => { let { state } = useLocation() console.info(state) - console.log(useParams()); - const { order_sn: colisn } = useParams(); - console.log('invoke customer profile+++++++++++++++++++++++++++++++++++++++++++++', colisn); - // const { customerOrderProfile: orderInfo } = useConversationState(); - const { loginUser: currentUser } = useAuthContext(); - const { quotes, contact, last_contact, ...order } = {}; // orderInfo; + const { order_sn: order_sn } = useParams() + console.log('invoke customer profile+++++++++++++++++++++++++++++++++++++++++++++', order_sn) + const { orderDetail, fetchOrderDetail } = useOrderStore() + const { loginUser: currentUser } = useAuthContext() + + useEffect(() => { + fetchOrderDetail(order_sn) + console.info('CustomerProfile.useEffect') + console.info(orderDetail) + }, []) return (
{ 最新报价 -

{quotes?.[0]?.lettertitle}

+

{'1st Japan Trip'}

-

+

- ); -}); -export default CustomerProfile; + ) +}) +export default CustomerProfile