fix: 商业号设置成功后更新到 store, storage

2.0/email-builder
Jimmy Liow 10 months ago
parent 1c6d6a16ef
commit 4d04914a08

@ -173,6 +173,7 @@ const useAuthStore = create(devtools((set, get) => ({
},
setWhatsAppBusiness: async (userId, whatsAppBusiness) => {
const { loginUser, saveUserSession } = get()
const postWABAUrl = `${API_HOST}/v2/set_whatsapp_info`
const params = {opi_sn: userId, whatsapp_waba: whatsAppBusiness};
@ -180,7 +181,13 @@ const useAuthStore = create(devtools((set, get) => ({
return fetchJSON(postWABAUrl, params)
.then(json => {
if (json.errcode === 0) {
console.info(json)
set(() => ({
loginUser: {
...loginUser,
whatsAppBusiness: whatsAppBusiness,
}
}))
saveUserSession()
} else {
throw new Error(json?.errmsg + ': ' + json.errcode)
}

@ -1,9 +1,13 @@
import { useEffect } from 'react'
import { Row, Col, Space, Descriptions, Avatar, Tag, Divider, List, Alert, Button, Flex, Select, Spin, Form, Typography, QRCode, Tooltip } from 'antd'
import { useEffect, useCallback } from 'react'
import { Row, Col, Space, Descriptions, Avatar, Tag, Divider, List, App, Button, Flex, Select, Spin, Form, Typography, QRCode, Tooltip } from 'antd'
import { UserOutlined, InfoCircleOutlined, CloseCircleFilled, ReloadOutlined, CheckCircleFilled } from '@ant-design/icons'
import useAuthStore from '@/stores/AuthStore'
function Profile() {
const { notification } = App.useApp()
const [wabaForm] = Form.useForm()
const [loginUser, setWhatsAppBusiness] = useAuthStore((state) => [state.loginUser, state.setWhatsAppBusiness])
useEffect(() => {
@ -12,6 +16,26 @@ function Profile() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const handelUpdateWABA = useCallback(() => {
console.info('handelUpdateWABA: %o', wabaForm.getFieldsValue())
setWhatsAppBusiness(loginUser.userId, wabaForm.getFieldsValue().whatsAppBusiness)
.then(() => {
notification.info({
message: 'Notification',
description: '商业号身份设置成功',
placement: 'top',
})
})
.catch(ex => {
notification.error({
message: 'Notification',
description: ex.message,
placement: 'top',
duration: 4,
})
})
}, [])
const customStatusRender = (info) => {
switch (info.status) {
case 'expired':
@ -85,28 +109,27 @@ function Profile() {
}>
<Form
layout='vertical'
// form={form}
form={wabaForm}
initialValues={{whatsAppBusiness: loginUser.whatsAppBusiness}}
>
<Form.Item>
<Form.Item name='whatsAppBusiness'>
<Select
defaultValue='8617607730395'
options={[
{
value: '8618174165365',
label: 'GH 客服(8618174165365)',
value: '+8617607730395',
label: 'GH 顾问(+8617607730395)',
},
{
value: '8617607730395',
label: 'GH 顾问(8617607730395)',
value: '+8618174165365',
label: '国际事业部(+8618174165365)',
},
{
value: '191477856351',
label: 'GH 客运(191477856351)',
value: 'GH 客运',
label: 'GH 客运()',
},
{
value: '国际事业部',
label: '国际事业部(无)',
disabled: true,
value: 'GH 客服',
label: 'GH 客服(无)',
},
{
value: 'CT 事业部',
@ -124,9 +147,7 @@ function Profile() {
<Form.Item>
<Button
type='primary'
onClick={() => {
setWhatsAppBusiness(383, 8617607730395)
}}>
onClick={handelUpdateWABA}>
保存
</Button>
</Form.Item>

Loading…
Cancel
Save