mirror of
https://github.com/Mail-0/Zero.git
synced 2026-07-01 08:16:28 +00:00
saving...
This commit is contained in:
@@ -30,11 +30,10 @@ export function CreateEmail() {
|
||||
const [resetEditorKey, setResetEditorKey] = React.useState(0);
|
||||
const [isDragging, setIsDragging] = React.useState(false);
|
||||
const [hasUnsavedChanges, setHasUnsavedChanges] = React.useState(false);
|
||||
const [isSaving, setIsSaving] = React.useState(false);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const [messageContent, setMessageContent] = React.useState('');
|
||||
const [draftId, setDraftId] = useQueryState('draftId');
|
||||
const [defaultValue, setDefaultValue] = React.useState<JSONContent | null>(null);
|
||||
const [editorReady, setEditorReady] = React.useState(false);
|
||||
|
||||
const { data: session } = useSession();
|
||||
const { data: connections } = useConnections();
|
||||
@@ -45,9 +44,9 @@ export function CreateEmail() {
|
||||
}, [session, connections]);
|
||||
|
||||
const userName =
|
||||
activeAccount?.name || session?.activeConnection?.name || session?.user.name || '';
|
||||
activeAccount?.name || session?.activeConnection?.name || session?.user?.name || '';
|
||||
const userEmail =
|
||||
activeAccount?.email || session?.activeConnection?.email || session?.user.email || '';
|
||||
activeAccount?.email || session?.activeConnection?.email || session?.user?.email || '';
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!draftId && !defaultValue) {
|
||||
@@ -61,7 +60,6 @@ export function CreateEmail() {
|
||||
},
|
||||
],
|
||||
});
|
||||
setEditorReady(true);
|
||||
}
|
||||
}, [draftId, defaultValue]);
|
||||
|
||||
@@ -144,19 +142,12 @@ export function CreateEmail() {
|
||||
setHasUnsavedChanges(true);
|
||||
};
|
||||
|
||||
const handleAttachment = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
if (e.target.files) {
|
||||
setAttachments([...attachments, ...Array.from(e.target.files)]);
|
||||
setHasUnsavedChanges(true);
|
||||
}
|
||||
};
|
||||
|
||||
const saveDraft = React.useCallback(async () => {
|
||||
if (!hasUnsavedChanges) return;
|
||||
if (!toEmails.length && !subjectInput && !messageContent) return;
|
||||
|
||||
try {
|
||||
setIsSaving(true);
|
||||
setIsLoading(true);
|
||||
const draftData = {
|
||||
to: toEmails.join(', '),
|
||||
subject: subjectInput,
|
||||
@@ -176,7 +167,7 @@ export function CreateEmail() {
|
||||
console.error('Error saving draft:', error);
|
||||
toast.error('Failed to save draft');
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [toEmails, subjectInput, messageContent, attachments, draftId, hasUnsavedChanges]);
|
||||
|
||||
@@ -211,6 +202,7 @@ export function CreateEmail() {
|
||||
}
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
await sendEmail({
|
||||
to: toEmails.join(','),
|
||||
subject: subjectInput,
|
||||
@@ -218,6 +210,7 @@ export function CreateEmail() {
|
||||
attachments: attachments,
|
||||
});
|
||||
|
||||
setIsLoading(false);
|
||||
toast.success(t('pages.createEmail.emailSentSuccessfully'));
|
||||
|
||||
setToInput('');
|
||||
@@ -241,6 +234,7 @@ export function CreateEmail() {
|
||||
setHasUnsavedChanges(false);
|
||||
} catch (error) {
|
||||
console.error('Error sending email:', error);
|
||||
setIsLoading(false);
|
||||
toast.error(t('pages.createEmail.failedToSendEmail'));
|
||||
}
|
||||
};
|
||||
@@ -322,6 +316,7 @@ export function CreateEmail() {
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
disabled={isLoading}
|
||||
className="text-muted-foreground hover:text-foreground ml-1 rounded-full"
|
||||
onClick={() => {
|
||||
setToEmails((emails) => emails.filter((_, i) => i !== index));
|
||||
@@ -333,6 +328,7 @@ export function CreateEmail() {
|
||||
</div>
|
||||
))}
|
||||
<input
|
||||
disabled={isLoading}
|
||||
type="email"
|
||||
className="text-md relative left-[3px] min-w-[120px] flex-1 bg-transparent placeholder:text-[#616161] placeholder:opacity-50 focus:outline-none"
|
||||
placeholder={toEmails.length ? '' : t('pages.createEmail.example')}
|
||||
@@ -361,6 +357,7 @@ export function CreateEmail() {
|
||||
{t('common.searchBar.subject')}
|
||||
</div>
|
||||
<input
|
||||
disabled={isLoading}
|
||||
type="text"
|
||||
className="text-md relative left-[7.5px] w-full bg-transparent placeholder:text-[#616161] placeholder:opacity-50 focus:outline-none"
|
||||
placeholder={t('common.searchBar.subject')}
|
||||
@@ -468,7 +465,9 @@ export function CreateEmail() {
|
||||
variant="default"
|
||||
className="h-9 w-9 overflow-hidden rounded-full"
|
||||
onClick={handleSendEmail}
|
||||
disabled={!toEmails.length || !messageContent.trim() || !subjectInput.trim()}
|
||||
disabled={
|
||||
isLoading || !toEmails.length || !messageContent.trim() || !subjectInput.trim()
|
||||
}
|
||||
>
|
||||
<ArrowUpIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user