feat: 读取登录账户的配置: whatsAppBusiness. 获取次商业号的模板

2.0/email-builder
Lei OT 1 year ago
parent d5e4c7ff99
commit 2fc8879bcd

@ -6,8 +6,11 @@ import { API_HOST } from '@/config';
import { isEmpty } from '@/utils/commons';
import dayjs from 'dayjs';
export const fetchTemplates = async () => {
const data = await fetchJSON(`${API_HOST}/listtemplates`);
/**
* @param {object} params { waba }
*/
export const fetchTemplates = async (params) => {
const data = await fetchJSON(`${API_HOST}/listtemplates`, params);
const canUseTemplates = (data?.result?.items || [])
.filter((_t) => _t.status === 'APPROVED')
.map((ele) => ({ ...ele, components_origin: ele.components, components: groupBy(ele.components, (_c) => _c.type.toLowerCase()) }));

@ -21,6 +21,8 @@ export const OSS_URL_CN = 'https://haina-sale-system.oss-cn-shenzhen.aliyuncs.co
export const OSS_URL_AP = 'https://hiana-crm.oss-ap-southeast-1.aliyuncs.com/WAMedia/';
export const OSS_URL = OSS_URL_AP;
export const DEFAULT_CHANNEL = 'waba'; // 默认渠道 waba email wa
const __BUILD_VERSION__ = `__BUILD_VERSION__`.replace(/"/g, '')
const __BUILD_DATE__ = `__BUILD_DATE__`;

@ -411,13 +411,13 @@ export const useConversationStore = create(
setInitial: (v) => set({ initialState: v }),
// side effects
fetchInitialData: async (userIds) => {
fetchInitialData: async ({userIds, whatsAppBusiness, ...loginUser}) => {
const { addToConversationList, setTemplates, setInitial, setClosedConversationList, setTags } = get();
// const conversationsList = await fetchConversationsList({ opisn: userIds });
// addToConversationList(conversationsList);
const templates = await fetchTemplates();
const templates = await fetchTemplates({ waba: whatsAppBusiness });
setTemplates(templates);
// const closedList = await fetchConversationsList({ opisn: userIds, session_enable: 0 });

@ -49,7 +49,7 @@ function AuthApp() {
appendRequestHeader('X-User-Id', loginUser.userId)
loadPageSpy(loginUser.username)
connectWebsocket(loginUser.userId)
fetchInitialData(loginUser.userId)
fetchInitialData(loginUser)
}
return () => {
disconnectWebsocket()

@ -110,7 +110,7 @@ const BubbleIM = ({ handlePreview, handleContactClick, setNewChatModalVisible, s
{...(message.sender === 'me'
? {
// styles: { backgroundColor: '#ccd4ae' },
notchStyle: { fill: '#ccd4ae' }, // todo: channel color '#d9fdd3'
notchStyle: { fill: '#ccd4ae' }, // todo: channel[WhatsApp] color '#d9fdd3'
replyButton: ['text', 'document', 'image'].includes(message.whatsapp_msg_type) && message.status !== 'failed' ? true : false,
}
: {})}

@ -28,6 +28,8 @@ const InputTemplate = ({ disabled = false, invokeSendMessage }) => {
const searchInputRef = useRef(null);
const { notification } = App.useApp();
const loginUser = useAuthStore((state) => state.loginUser);
const { whatsAppBusiness } = loginUser;
loginUser.usernameEN = loginUser.accountList[0].OPI_NameEN.split(' ')?.[0] || loginUser.username;
const currentConversation = useConversationStore((state) => state.currentConversation);
const templates = useConversationStore((state) => state.templates);

@ -8,16 +8,19 @@ import useConversationStore from '@/stores/ConversationStore';
import { useShallow } from 'zustand/react/shallow';
import useStyleStore from '@/stores/StyleStore';
import { isEmpty } from '@/utils/commons';
import { DEFAULT_CHANNEL } from '@/config';
const DEFAULT_CHANNEL = 'waba';
const Wabas = [
{ key: 'Global Highlights', label: 'Global Highlights' },
{ key: 'Global Highlights-Multi', label: 'Global Highlights-Multi' },
];
const Wabas_mapped = Wabas.reduce((acc, cur) => ({...acc, [cur.key]: cur}), {});
/**
* @ignore
* 不在此处配置, 在个人档案页面配置
*/
const WABASwitcher = ({ onSelect, }) => {
const [pickV, setPickV] = useState({}); // todo: ? ?
const [pickV, setPickV] = useState({}); // review: ? ?
return (
<Dropdown
// trigger={['contextMenu', 'hover']}
@ -41,6 +44,7 @@ const WABASwitcher = ({ onSelect, }) => {
const ReplyWrapper = () => {
const [mobile] = useStyleStore(state => [state.mobile]);
const [activeChannel, setActiveChannel] = useState(DEFAULT_CHANNEL);
const onChannelTabsChange = (activeKey) => {
setActiveChannel(activeKey);
@ -68,7 +72,7 @@ const ReplyWrapper = () => {
const replyTypes = [
// { key: 'waba', label: mobile ? '' : (<WABASwitcher />), icon: <WABIcon />, children: <InputComposer channel={'waba'} /> },
{ key: 'waba', label: mobile ? '' : 'WA商业号-Global Highlights', icon: <WABIcon />, children: <InputComposer channel={'waba'} /> }, // todo:
{ key: 'waba', label: mobile ? '' : 'WA商业号', icon: <WABIcon />, children: <InputComposer channel={'waba'} /> },
{ key: 'email', label: mobile ? '' : 'Email', icon: <MailOutlined className='text-indigo-500' />, children: <EmailSwitcher /> },
// { key: 'whatsapp', label: mobile ? '' : 'WhatsApp', icon: <WhatsAppOutlined className='text-whatsapp' />, children: <InputComposer channel={'whatsapp'} /> },
{ key: 'wa', label: mobile ? '' : 'WhatsApp', icon: <WhatsAppOutlined className='text-whatsapp' />, children: <div className='p-2 py-4 text-center text-whatsapp bg-gray-200 rounded rounded-b-none border-gray-300 border-solid border border-b-0 border-x-0'>敬请期待</div> },

Loading…
Cancel
Save