You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
937 B
JavaScript
33 lines
937 B
JavaScript
8 months ago
|
import { useState, useEffect } from 'react'
|
||
|
import { isEmpty } from '@/utils/commons'
|
||
|
import { getEmailDetailAction } from '@/actions/EmailActions'
|
||
|
|
||
|
/**
|
||
|
* @param mai_sn 邮件编号ID
|
||
|
* @param data 直接传递, 不重复获取
|
||
|
* * 在详情点击`回复`呼出编辑时
|
||
|
*/
|
||
|
export const useEmailDetail = (mai_sn, data) => {
|
||
|
const [loading, setLoading] = useState(false)
|
||
|
const [mailData, setMailData] = useState({ loading, info: {}, content: '', attachments: [] })
|
||
|
useEffect(() => {
|
||
|
const getEmailDetail = async () => {
|
||
|
if (isEmpty(mai_sn)) {
|
||
|
return false
|
||
|
}
|
||
|
try {
|
||
|
setLoading(true)
|
||
|
const data = await getEmailDetailAction({ mai_sn })
|
||
|
setMailData(data)
|
||
|
setLoading(false)
|
||
|
} catch (err) {
|
||
|
setLoading(false)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (isEmpty(data)) getEmailDetail()
|
||
|
else setMailData(data)
|
||
|
}, [mai_sn])
|
||
|
return mailData
|
||
|
}
|