filter and search inbox
This commit is contained in:
@@ -3,6 +3,7 @@ import { Filter, CloseCircle } from 'iconsax-react';
|
|||||||
import DatePicker from './DatePicker';
|
import DatePicker from './DatePicker';
|
||||||
import Input from './Input';
|
import Input from './Input';
|
||||||
import Select, { ItemsSelectType } from './Select';
|
import Select, { ItemsSelectType } from './Select';
|
||||||
|
import moment from 'moment-jalaali'
|
||||||
|
|
||||||
// تعریف نوع داده برای فیلدهای مختلف
|
// تعریف نوع داده برای فیلدهای مختلف
|
||||||
export type DateFieldType = {
|
export type DateFieldType = {
|
||||||
@@ -91,7 +92,7 @@ const Filters: FC<FiltersProps> = ({
|
|||||||
<DatePicker
|
<DatePicker
|
||||||
key={field.name}
|
key={field.name}
|
||||||
placeholder={field.placeholder}
|
placeholder={field.placeholder}
|
||||||
onChange={(value) => handleChange(field.name, value)}
|
onChange={(value) => handleChange(field.name, moment(value, 'jYYYY/jMM/jDD').format('YYYY-MM-DD'))}
|
||||||
defaultValue={currentValue || field.defaultValue || ''}
|
defaultValue={currentValue || field.defaultValue || ''}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -202,16 +202,16 @@ const List: FC = () => {
|
|||||||
|
|
||||||
<Filters
|
<Filters
|
||||||
fields={[
|
fields={[
|
||||||
{ type: 'date', name: 'dateFrom', placeholder: t('received.from_date') },
|
{ type: 'date', name: 'datestart', placeholder: t('received.from_date') },
|
||||||
{ type: 'date', name: 'dateTo', placeholder: t('received.to_date') },
|
{ type: 'date', name: 'dateend', placeholder: t('received.to_date') },
|
||||||
{
|
{
|
||||||
type: 'select',
|
type: 'select',
|
||||||
name: 'isRead',
|
name: 'unseen',
|
||||||
placeholder: t('received.all'),
|
placeholder: t('received.all'),
|
||||||
options: [
|
options: [
|
||||||
{ value: '', label: t('received.all') },
|
{ value: '', label: t('received.all') },
|
||||||
{ value: 'true', label: t('received.read') },
|
{ value: 'false', label: t('received.read') },
|
||||||
{ value: 'false', label: t('received.unread') }
|
{ value: 'true', label: t('received.unread') }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ type: 'input', name: 'search', placeholder: t('received.search') }
|
{ type: 'input', name: 'search', placeholder: t('received.search') }
|
||||||
|
|||||||
@@ -27,7 +27,19 @@ export const getDraft = async (
|
|||||||
export const getInbox = async (
|
export const getInbox = async (
|
||||||
query: MessageListQueryDto
|
query: MessageListQueryDto
|
||||||
): Promise<InboxResponse> => {
|
): Promise<InboxResponse> => {
|
||||||
const { data } = await axios.get(`/email/messages/inbox`, { params: query });
|
console.log("query", query);
|
||||||
|
|
||||||
|
const isSearch =
|
||||||
|
!!query.search ||
|
||||||
|
!!query.datestart ||
|
||||||
|
query.dateend ||
|
||||||
|
query.unseen ||
|
||||||
|
query.from;
|
||||||
|
const url = isSearch ? "search" : "messages/inbox";
|
||||||
|
|
||||||
|
const { data } = await axios.get(`/email/${url}`, {
|
||||||
|
params: query,
|
||||||
|
});
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -41,105 +53,75 @@ export const getMessageDetail = async (
|
|||||||
return data.data.message;
|
return data.data.message;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteMessage = async (messageId: string): Promise<void> => {
|
export const deleteMessage = async (messageId: string) => {
|
||||||
const { data } = await axios.delete(`/email/messages/${messageId}`);
|
const { data } = await axios.delete(`/email/messages/${messageId}`);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const moveToArchive = async (
|
export const moveToArchive = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/archive?mailbox=${mailbox}`
|
`/email/messages/${messageId}/archive?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const moveToTrash = async (
|
export const moveToTrash = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/trash?mailbox=${mailbox}`
|
`/email/messages/${messageId}/trash?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const moveToFavorite = async (
|
export const moveToFavorite = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/favorite?mailbox=${mailbox}`
|
`/email/messages/${messageId}/favorite?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const moveToJunk = async (
|
export const moveToJunk = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/junk?mailbox=${mailbox}`
|
`/email/messages/${messageId}/junk?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const moveToNotJunk = async (
|
export const moveToNotJunk = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/not-junk?mailbox=${mailbox}`
|
`/email/messages/${messageId}/not-junk?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const restoreMessage = async (
|
export const restoreMessage = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/restore?mailbox=${mailbox}`
|
`/email/messages/${messageId}/restore?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const unFavoriteMessage = async (
|
export const unFavoriteMessage = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/unfavorite?mailbox=${mailbox}`
|
`/email/messages/${messageId}/unfavorite?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const unArchiveMessage = async (
|
export const unArchiveMessage = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/unarchive?mailbox=${mailbox}`
|
`/email/messages/${messageId}/unarchive?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const markAsRead = async (
|
export const markAsRead = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/seen?mailbox=${mailbox}`
|
`/email/messages/${messageId}/seen?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const markAsUnread = async (
|
export const markAsUnread = async (messageId: string, mailbox: string) => {
|
||||||
messageId: string,
|
|
||||||
mailbox: string
|
|
||||||
): Promise<void> => {
|
|
||||||
const { data } = await axios.patch(
|
const { data } = await axios.patch(
|
||||||
`/email/messages/${messageId}/unseen?mailbox=${mailbox}`
|
`/email/messages/${messageId}/unseen?mailbox=${mailbox}`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -56,15 +56,15 @@ export interface SendEmailDto {
|
|||||||
export interface MessageListQueryDto {
|
export interface MessageListQueryDto {
|
||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
order?: string;
|
|
||||||
search?: string;
|
search?: string;
|
||||||
from?: string;
|
from?: string;
|
||||||
subject?: string;
|
subject?: string;
|
||||||
dateFrom?: string;
|
datestart?: string;
|
||||||
dateTo?: string;
|
dateend?: string;
|
||||||
hasAttachment?: boolean;
|
attachments?: boolean;
|
||||||
isRead?: boolean;
|
unseen?: boolean;
|
||||||
isFlagged?: boolean;
|
flagged?: boolean;
|
||||||
|
order?: "asc" | "desc";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updated types based on actual API response
|
// Updated types based on actual API response
|
||||||
|
|||||||
Reference in New Issue
Block a user