feat: useEmailList hooks
parent
1d513ec038
commit
efae99e81e
@ -0,0 +1,134 @@
|
||||
import { getEmailDirAction } from '@/actions/EmailActions'
|
||||
import { buildTree, isEmpty, readIndexDB, writeIndexDB, createIndexedDBStore } from '@/utils/commons'
|
||||
|
||||
/**
|
||||
* Email
|
||||
*/
|
||||
const emailSlice = (set, get) => ({
|
||||
emailMsg: { id: -1, conversationid: '', actionId: '', order_opi: '', coli_sn: '', msgOrigin: {} },
|
||||
setEmailMsg: (emailMsg) => {
|
||||
const { editorOpen } = get()
|
||||
return editorOpen ? false : set({ emailMsg }) // 已经打开的不更新
|
||||
},
|
||||
detailPopupOpen: false,
|
||||
setDetailOpen: (v) => set({ detailPopupOpen: v }),
|
||||
openDetail: () => set(() => ({ detailPopupOpen: true })),
|
||||
closeDetail: () => set(() => ({ detailPopupOpen: false })),
|
||||
editorOpen: false,
|
||||
setEditorOpen: (v) => set({ editorOpen: v }),
|
||||
openEditor: () => set(() => ({ editorOpen: true })),
|
||||
closeEditor: () => set(() => ({ editorOpen: false })),
|
||||
|
||||
// EmailEditorPopup 组件的 props
|
||||
// @property {string} fromEmail - 发件人邮箱
|
||||
// @property {string} fromUser - 发件人用户
|
||||
// @property {string} fromOrder - 发件订单
|
||||
// @property {string} toEmail - 收件人邮箱
|
||||
// @property {string} conversationid - 会话ID
|
||||
// @property {string} quoteid - 引用邮件ID
|
||||
// @property {object} draft - 草稿
|
||||
// @property {string} action - reply / forward / new / edit
|
||||
// @property {string} oid - coli_sn
|
||||
// @property {object} mailData - 邮件内容
|
||||
// @property {string} receiverName - 收件人称呼
|
||||
emailEdiorProps: new Map(),
|
||||
setEditorProps: (v) => {
|
||||
const { emailEdiorProps } = get()
|
||||
const uniqueKey = v.quoteid || Date.now().toString(32)
|
||||
const currentEditValue = { ...v, key: `${v.action}-${uniqueKey}` }
|
||||
const news = new Map(emailEdiorProps).set(currentEditValue.key, currentEditValue)
|
||||
for (const [key, value] of news.entries()) {
|
||||
console.log(value)
|
||||
}
|
||||
return set((state) => ({ emailEdiorProps: news, currentEditKey: currentEditValue.key, currentEditValue }))
|
||||
// return set((state) => ({ emailEdiorProps: { ...state.emailEdiorProps, ...v } }))
|
||||
},
|
||||
closeEditor1: (key) => {
|
||||
const { emailEdiorProps } = get()
|
||||
const newProps = new Map(emailEdiorProps)
|
||||
newProps.delete(key)
|
||||
return set(() => ({ emailEdiorProps: newProps }))
|
||||
},
|
||||
clearEditor: () => {
|
||||
return set(() => ({ emailEdiorProps: new Map() }))
|
||||
},
|
||||
currentEditKey: '',
|
||||
setCurrentEditKey: (key) => {
|
||||
const { emailEdiorProps, setCurrentEditValue } = get()
|
||||
const value = emailEdiorProps.get(key)
|
||||
setCurrentEditValue(value)
|
||||
return set(() => ({ currentEditKey: key }))
|
||||
},
|
||||
currentEditValue: {},
|
||||
setCurrentEditValue: (v) => {
|
||||
return set(() => ({ currentEditValue: v }))
|
||||
},
|
||||
|
||||
// mailboxNestedDirs: new Map(),
|
||||
// setMailboxNestedDirs: (opi, dirs) => {
|
||||
// const { mailboxNestedDirs } = get()
|
||||
// const news = mailboxNestedDirs.set(opi, dirs)
|
||||
// return set(() => ({ mailboxNestedDirs: news }))
|
||||
// },
|
||||
|
||||
currentMailboxDEI: 0,
|
||||
setCurrentMailboxDEI: (id) => {
|
||||
return set(() => ({ currentMailboxDEI: id }))
|
||||
},
|
||||
currentMailboxOPI: 0,
|
||||
setCurrentMailboxOPI: (id) => {
|
||||
return set(() => ({ currentMailboxOPI: id }))
|
||||
},
|
||||
|
||||
mailboxNestedDirsActive: [],
|
||||
setMailboxNestedDirsActive: (dir) => {
|
||||
return set(() => ({ mailboxNestedDirsActive: dir }))
|
||||
},
|
||||
|
||||
mailboxActiveNode: {},
|
||||
setMailboxActiveNode: (node) => {
|
||||
return set(() => ({ mailboxActiveNode: node }))
|
||||
},
|
||||
|
||||
mailboxList: [],
|
||||
setMailboxList: (list) => {
|
||||
return set(() => ({ mailboxList: list }))
|
||||
},
|
||||
mailboxActiveMAI: 0,
|
||||
setMailboxActiveMAI: (mai) => {
|
||||
return set(() => ({ mailboxActiveMAI: mai }))
|
||||
},
|
||||
|
||||
getOPIEmailDir: async (opi_sn = 0) => {
|
||||
// console.log('🌐requesting opi dir', opi_sn, typeof opi_sn)
|
||||
const { setMailboxNestedDirsActive } = get()
|
||||
const readCache = await readIndexDB(Number(opi_sn), 'dirs', 'mailbox')
|
||||
// console.log(readCache);
|
||||
// setMailboxNestedDirs(Number(opi_sn), readCache.tree)
|
||||
let isNeedRefresh = false
|
||||
if (!isEmpty(readCache)) {
|
||||
setMailboxNestedDirsActive(readCache?.tree || [])
|
||||
isNeedRefresh = Date.now() - readCache.timestamp > 4 * 60 * 60 * 1000
|
||||
} else if (isEmpty(readCache) || isNeedRefresh) {
|
||||
// > {4} 更新
|
||||
const x = await getEmailDirAction({ opi_sn })
|
||||
const mailboxSort = x //.sort(sortBy('MDR_Order'));
|
||||
let tree = buildTree(mailboxSort, { key: 'VKey', parent: 'VParent', name: 'VName', iconIndex: 'ImageIndex', rootKeys: [1], ignoreKeys: [-227001, -227002] })
|
||||
tree = tree.filter((ele) => ele.key !== 1)
|
||||
writeIndexDB([{ key: Number(opi_sn), tree }], 'dirs', 'mailbox')
|
||||
// setMailboxNestedDirs(Number(opi_sn), tree)
|
||||
setMailboxNestedDirsActive(tree)
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
||||
async initMailbox({ opi_sn, dei_sn, userId }) {
|
||||
const { setCurrentMailboxOPI, setCurrentMailboxDEI, getOPIEmailDir } = get()
|
||||
createIndexedDBStore(['dirs', 'maillist', 'mailinfo'], 'mailbox')
|
||||
setCurrentMailboxOPI(opi_sn)
|
||||
setCurrentMailboxDEI(dei_sn)
|
||||
getOPIEmailDir(userId)
|
||||
},
|
||||
|
||||
})
|
||||
export default emailSlice
|
@ -0,0 +1,27 @@
|
||||
import { StarTwoTone, CalendarTwoTone, FolderOutlined, DeleteOutlined, ClockCircleOutlined, FormOutlined, DatabaseOutlined } from '@ant-design/icons'
|
||||
import { InboxIcon, MailUnreadIcon, SendPlaneFillIcon } from '@/components/Icons'
|
||||
|
||||
const EmailDirTypeIcons = {
|
||||
0: { component: FolderOutlined, color: '#ffe78f', className: 'text-blue-500' },
|
||||
1: { component: FolderOutlined, color: '#ffe78f', className: 'text-blue-500' },
|
||||
3: { component: InboxIcon, color: '', className: 'text-indigo-500' },
|
||||
17: { component: InboxIcon, color: '', className: 'text-indigo-500' },
|
||||
11: { component: MailUnreadIcon, color: '', className: 'text-indigo-500' },
|
||||
4: { component: SendPlaneFillIcon, color: '', className: 'text-primary' },
|
||||
2: { component: ClockCircleOutlined, color: '', className: 'text-yellow-500' },
|
||||
5: { component: FormOutlined, color: '', className: 'text-blue-500' },
|
||||
7: { component: DeleteOutlined, color: '', className: 'text-red-500' },
|
||||
// '3': { component: MailCheckIcon, color: '', className: 'text-yellow-600' },
|
||||
12: { component: DatabaseOutlined, color: '', className: 'text-blue-600' },
|
||||
13: { component: () => null, color: '', className: '' },
|
||||
14: { component: () => '❗', color: '', className: '' }, // 240002 较重要/高品牌价值客户
|
||||
15: { component: () => '❣️', color: '', className: '' }, // 240003 很重要/高订单价值客户
|
||||
}
|
||||
|
||||
export const MailboxDirIcon = ({ type }) => {
|
||||
const Icon = EmailDirTypeIcons[type || '13']?.component || EmailDirTypeIcons['13'].component
|
||||
const className = EmailDirTypeIcons[type || '13']?.className || EmailDirTypeIcons['13'].className
|
||||
return <Icon className={className} />
|
||||
}
|
||||
|
||||
export default MailboxDirIcon
|
Loading…
Reference in New Issue