diff --git a/src/stores/AuthStore.js b/src/stores/AuthStore.js index 62394e7..094b887 100644 --- a/src/stores/AuthStore.js +++ b/src/stores/AuthStore.js @@ -176,11 +176,11 @@ const useAuthStore = create(devtools((set, get) => ({ ) }, - setWhatsAppBusiness: async (userId, whatsAppBusiness) => { + setWhatsAppProfile: async (userId, whatsAppBusiness, whatsAppNo) => { const { loginUser, saveUserSession } = get() const postWABAUrl = `${API_HOST}/v2/set_whatsapp_info` - const params = {opi_sn: userId, whatsapp_waba: whatsAppBusiness}; + const params = {opi_sn: userId, whatsapp_waba: whatsAppBusiness, whatsapp_wa: whatsAppNo}; return fetchJSON(postWABAUrl, params) .then(json => { @@ -188,6 +188,7 @@ const useAuthStore = create(devtools((set, get) => ({ set(() => ({ loginUser: { ...loginUser, + whatsAppNo: whatsAppNo, whatsAppBusiness: whatsAppBusiness, } })) diff --git a/src/views/accounts/Profile.jsx b/src/views/accounts/Profile.jsx index e33d750..bb59c0a 100644 --- a/src/views/accounts/Profile.jsx +++ b/src/views/accounts/Profile.jsx @@ -10,11 +10,12 @@ function Profile() { const { notification } = App.useApp() const [wabaForm] = Form.useForm() - const [loginUser, setWhatsAppBusiness, isPermitted] = useAuthStore((state) => [ - state.loginUser, state.setWhatsAppBusiness, state.isPermitted + const [loginUser, setWhatsAppProfile, isPermitted] = useAuthStore((state) => [ + state.loginUser, state.setWhatsAppProfile, state.isPermitted ]) - const [qrCode, setQRCode] = useState('') + const [qrCode, setQRCode] = useState('expired') + const [qrStatus, setQRStatus] = useState('expired') useEffect(() => { // 测试错误捕获: @@ -23,11 +24,12 @@ function Profile() { }, []) const handelUpdateWABA = useCallback(() => { - setWhatsAppBusiness(loginUser.userId, wabaForm.getFieldsValue().whatsAppBusiness) + const formValues = wabaForm.getFieldsValue() + setWhatsAppProfile(loginUser.userId, formValues.whatsAppBusiness, formValues.whatsAppNo) .then(() => { notification.info({ message: 'Notification', - description: '商业号身份设置成功', + description: 'WhatsApp 配置成功', placement: 'top', }) }) @@ -48,8 +50,8 @@ function Profile() { 'http://localhost:3031/api/v1/whatsapp/channels/qrcode', { phone }) .then(r => { - console.info(r) setQRCode(r.result.qr) + setQRStatus('active') }) .catch(ex => { console.error(ex) @@ -57,6 +59,7 @@ function Profile() { }, []) const customStatusRender = (info) => { + console.info(info) switch (info.status) { case 'expired': return ( @@ -65,22 +68,14 @@ function Profile() { style={{ color: '#52c41a', }} - />{' '} - 8618754124786 已登录 + />已过期
-
) - case 'loading': - return ( -Loading...
-