mail page rest dang
This commit is contained in:
parent
273442d42c
commit
287941f42f
@ -44,7 +44,7 @@ export async function GET(req: NextRequest) {
|
|||||||
date: new Date().toISOString(),
|
date: new Date().toISOString(),
|
||||||
isUnread: true
|
isUnread: true
|
||||||
}],
|
}],
|
||||||
mailUrl: `${nextcloudUrl}/apps/mail/box/unified`
|
mailUrl: `${nextcloudUrl}/apps/courrier/box/unified`
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
|
|||||||
@ -22,7 +22,7 @@ export default function MailLoginPage() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/mail/login', {
|
const response = await fetch('/api/courrier/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@ -429,13 +429,13 @@ export default function CourrierPage() {
|
|||||||
const checkCredentials = async () => {
|
const checkCredentials = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('Checking for stored credentials...');
|
console.log('Checking for stored credentials...');
|
||||||
const response = await fetch('/api/mail');
|
const response = await fetch('/api/courrier');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
const errorData = await response.json();
|
||||||
console.log('API response error:', errorData);
|
console.log('API response error:', errorData);
|
||||||
if (errorData.error === 'No stored credentials found') {
|
if (errorData.error === 'No stored credentials found') {
|
||||||
console.log('No credentials found, redirecting to login...');
|
console.log('No credentials found, redirecting to login...');
|
||||||
router.push('/mail/login');
|
router.push('/courrier/login');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error(errorData.error || 'Failed to check credentials');
|
throw new Error(errorData.error || 'Failed to check credentials');
|
||||||
@ -463,7 +463,7 @@ export default function CourrierPage() {
|
|||||||
}
|
}
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
const response = await fetch(`/api/mail?folder=${currentView}&page=${page}&limit=${emailsPerPage}`);
|
const response = await fetch(`/api/courrier?folder=${currentView}&page=${page}&limit=${emailsPerPage}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to load emails');
|
throw new Error('Failed to load emails');
|
||||||
}
|
}
|
||||||
@ -557,7 +557,7 @@ export default function CourrierPage() {
|
|||||||
setSelectedEmail(email);
|
setSelectedEmail(email);
|
||||||
|
|
||||||
// Fetch the full email content
|
// Fetch the full email content
|
||||||
const response = await fetch(`/api/mail/${emailId}`);
|
const response = await fetch(`/api/courrier/${emailId}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch full email content');
|
throw new Error('Failed to fetch full email content');
|
||||||
}
|
}
|
||||||
@ -575,7 +575,7 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
// Try to mark as read in the background
|
// Try to mark as read in the background
|
||||||
try {
|
try {
|
||||||
const markReadResponse = await fetch(`/api/mail/mark-read`, {
|
const markReadResponse = await fetch(`/api/courrier/mark-read`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -630,7 +630,7 @@ export default function CourrierPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/mail/bulk-actions', {
|
const response = await fetch('/api/courrier/bulk-actions', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -673,7 +673,7 @@ export default function CourrierPage() {
|
|||||||
// Add handleDeleteConfirm function
|
// Add handleDeleteConfirm function
|
||||||
const handleDeleteConfirm = async () => {
|
const handleDeleteConfirm = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/mail/bulk-actions', {
|
const response = await fetch('/api/courrier/bulk-actions', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -1221,7 +1221,7 @@ export default function CourrierPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/mail/send', {
|
const response = await fetch('/api/courrier/send', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -1271,7 +1271,7 @@ export default function CourrierPage() {
|
|||||||
if (!email) return;
|
if (!email) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/mail/toggle-star', {
|
const response = await fetch('/api/courrier/toggle-star', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -1369,7 +1369,7 @@ export default function CourrierPage() {
|
|||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
|
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
|
||||||
|
|
||||||
const response = await fetch(`/api/mail?folder=${encodeURIComponent(newMailbox)}&page=1&limit=${emailsPerPage}`, {
|
const response = await fetch(`/api/courrier?folder=${encodeURIComponent(newMailbox)}&page=1&limit=${emailsPerPage}`, {
|
||||||
signal: controller.signal
|
signal: controller.signal
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,116 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
|
|
||||||
export default function MailLoginPage() {
|
|
||||||
const router = useRouter();
|
|
||||||
const [email, setEmail] = useState('');
|
|
||||||
const [password, setPassword] = useState('');
|
|
||||||
const [host, setHost] = useState('mail.infomaniak.com');
|
|
||||||
const [port, setPort] = useState('993');
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
setError('');
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/mail/login', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
host,
|
|
||||||
port,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(data.error || 'Failed to connect to email server');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect to mail page
|
|
||||||
router.push('/mail');
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : 'An error occurred');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
|
||||||
<Card className="w-full max-w-md">
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>Email Configuration</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="email">Email</Label>
|
|
||||||
<Input
|
|
||||||
id="email"
|
|
||||||
type="email"
|
|
||||||
value={email}
|
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="password">Password</Label>
|
|
||||||
<Input
|
|
||||||
id="password"
|
|
||||||
type="password"
|
|
||||||
value={password}
|
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="host">IMAP Host</Label>
|
|
||||||
<Input
|
|
||||||
id="host"
|
|
||||||
type="text"
|
|
||||||
value={host}
|
|
||||||
onChange={(e) => setHost(e.target.value)}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="port">IMAP Port</Label>
|
|
||||||
<Input
|
|
||||||
id="port"
|
|
||||||
type="text"
|
|
||||||
value={port}
|
|
||||||
onChange={(e) => setPort(e.target.value)}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{error && (
|
|
||||||
<div className="text-red-500 text-sm">{error}</div>
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
className="w-full"
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
{loading ? 'Connecting...' : 'Connect'}
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
1778
app/mail/page.tsx
1778
app/mail/page.tsx
File diff suppressed because it is too large
Load Diff
@ -72,7 +72,7 @@ export function Email() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
setEmails(validatedEmails);
|
setEmails(validatedEmails);
|
||||||
setMailUrl(data.mailUrl || 'https://espace.slm-lab.net/apps/mail/');
|
setMailUrl(data.mailUrl || 'https://espace.slm-lab.net/apps/courrier/');
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Error fetching emails');
|
setError(err instanceof Error ? err.message : 'Error fetching emails');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user