diff --git a/src/pages/received/hooks/useEmailData.tsx b/src/pages/received/hooks/useEmailData.tsx
index e0a938b..2111107 100644
--- a/src/pages/received/hooks/useEmailData.tsx
+++ b/src/pages/received/hooks/useEmailData.tsx
@@ -28,6 +28,7 @@ export const useGetInbox = (query: MessageListQueryDto) => {
queryFn: () => api.getInbox(query),
staleTime: 0, // Always fetch fresh data
refetchOnWindowFocus: true,
+ enabled: query.enabled ?? true
});
};
@@ -136,4 +137,10 @@ export const useMarkAllRead = () => {
return useMutation({
mutationFn: () => api.markAllRead(),
});
+};
+
+export const useDownloadEmail = () => {
+ return useMutation({
+ mutationFn: ({ messageId, mailbox }: { messageId: number; mailbox: string }) => api.downloadEmail(messageId, mailbox),
+ });
};
\ No newline at end of file
diff --git a/src/pages/received/service/EmailService.ts b/src/pages/received/service/EmailService.ts
index 41a3768..947876b 100644
--- a/src/pages/received/service/EmailService.ts
+++ b/src/pages/received/service/EmailService.ts
@@ -168,3 +168,13 @@ export const markAllRead = async () => {
);
return data;
};
+
+export const downloadEmail = async (messageId: number, mailbox: string) => {
+ const {
+ data,
+ } = await axios.get(
+ `/email/messages/${messageId}/download?mailbox=${mailbox}`,
+ { responseType: "blob" }
+ );
+ return data;
+};
diff --git a/src/pages/received/types/Types.ts b/src/pages/received/types/Types.ts
index 44cd636..ed9b3a4 100644
--- a/src/pages/received/types/Types.ts
+++ b/src/pages/received/types/Types.ts
@@ -66,6 +66,7 @@ export interface MessageListQueryDto {
unseen?: boolean;
flagged?: boolean;
order?: "asc" | "desc";
+ enabled?: boolean;
}
// Updated types based on actual API response
diff --git a/src/shared/Header.tsx b/src/shared/Header.tsx
index 9a65804..662929f 100644
--- a/src/shared/Header.tsx
+++ b/src/shared/Header.tsx
@@ -10,6 +10,7 @@ import { Paths } from '@/utils/Paths'
import SideBarItem from './SideBarItem'
import AvatarImage from '@/assets/images/avatar_image.png'
import { useGetProfile } from '@/pages/profile/hooks/useProfileData'
+import { useGetInbox } from '@/pages/received/hooks/useEmailData'
const Header: FC = () => {
@@ -20,6 +21,11 @@ const Header: FC = () => {
const [inputFocused, setInputFocused] = useState(false)
const [showMobileSearch, setShowMobileSearch] = useState(false)
const { pathname } = useLocation()
+ const { data: inboxData } = useGetInbox({
+ limit: 10,
+ search: search,
+ enabled: !!search,
+ })
const { t } = useTranslation('global')
const { setOpenSidebar, openSidebar } = useSharedStore()
@@ -33,6 +39,19 @@ const Header: FC = () => {
}
}
+ const clearSearch = () => {
+ setSearch('')
+ setShowSearchResults(false)
+ setInputFocused(false)
+ }
+
+ const clearSearchMobile = () => {
+ setSearch('')
+ setShowSearchResults(false)
+ setInputFocused(false)
+ setShowMobileSearch(false)
+ }
+
const handleInputFocus = () => {
setInputFocused(true)
if (search) {
@@ -66,8 +85,7 @@ const Header: FC = () => {
}
}, 100)
} else {
- setSearch('')
- setShowSearchResults(false)
+ clearSearch()
}
}
@@ -86,10 +104,10 @@ const Header: FC = () => {
mobileSearchContainer && !mobileSearchContainer.contains(e.target as Node) &&
mobileSearchInput && !mobileSearchInput.contains(e.target as Node);
- if ((searchContainer && searchInput && isClickOutsideDesktopSearch) ||
- (mobileSearchContainer && mobileSearchInput && isClickOutsideMobileSearch)) {
- setShowSearchResults(false)
- setInputFocused(false)
+ if (searchContainer && searchInput && isClickOutsideDesktopSearch) {
+ clearSearch()
+ } else if (mobileSearchContainer && mobileSearchInput && isClickOutsideMobileSearch) {
+ clearSearchMobile()
}
}
@@ -122,9 +140,43 @@ const Header: FC = () => {
id="search-dropdown-container"
className='absolute z-20 mt-1 w-full bg-white rounded-xl shadow-lg max-h-80 overflow-y-auto'
>
-
- نتیجهای یافت نشد
-
+ {inboxData?.data?.results && inboxData.data.results.length > 0 ? (
+
+ {inboxData.data.results.slice(0, 10).map((message) => (
+
+
+
+ {!message.seen && (
+
+ )}
+
+ {message.from.name || message.from.address}
+
+
+
+ {message.subject || 'بدون موضوع'}
+
+
+ {message.intro}
+
+
+
+ {new Date(message.date).toLocaleDateString('fa-IR')}
+
+
+ ))}
+
+
+ ) : (
+
+ نتیجهای یافت نشد
+
+ )}
)}