From 4fa5d97ae9d9577d4512a5da49f4bf2b5d23d995 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Wed, 19 Feb 2025 20:23:34 +0100 Subject: [PATCH] structuring --- src/app/calendar/page.tsx | 2 +- .../calendar}/postDialog.tsx | 6 +-- .../calendar}/timeSelect.tsx | 0 .../dashboard}/accountStatus.tsx | 4 +- .../dashboard}/engagement.tsx | 0 src/{components => app/dashboard}/ideas.tsx | 4 +- src/app/dashboard/page.tsx | 10 ++--- .../dashboard}/recentPosts.tsx | 4 +- src/app/login/page.tsx | 45 ++++++++++--------- src/components/icons.tsx | 42 ----------------- 10 files changed, 38 insertions(+), 79 deletions(-) rename src/{components => app/calendar}/postDialog.tsx (97%) rename src/{components => app/calendar}/timeSelect.tsx (100%) rename src/{components => app/dashboard}/accountStatus.tsx (92%) rename src/{components => app/dashboard}/engagement.tsx (100%) rename src/{components => app/dashboard}/ideas.tsx (88%) rename src/{components => app/dashboard}/recentPosts.tsx (93%) diff --git a/src/app/calendar/page.tsx b/src/app/calendar/page.tsx index 5d4c165..b88a7a1 100644 --- a/src/app/calendar/page.tsx +++ b/src/app/calendar/page.tsx @@ -19,7 +19,7 @@ import { import { PlusCircle, Trash } from 'lucide-react'; import { format, parse } from 'date-fns'; -import PostDialog, { today } from '@/components/postDialog'; +import PostDialog, { today } from './postDialog'; import axios from 'axios'; import Cookies from 'js-cookie'; import { Schedule } from '@/utils'; diff --git a/src/components/postDialog.tsx b/src/app/calendar/postDialog.tsx similarity index 97% rename from src/components/postDialog.tsx rename to src/app/calendar/postDialog.tsx index cf5ef31..fa25a01 100644 --- a/src/components/postDialog.tsx +++ b/src/app/calendar/postDialog.tsx @@ -18,11 +18,11 @@ import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { format } from 'date-fns'; import { CalendarIcon } from 'lucide-react'; -import { Calendar } from './ui/calendar'; +import { Calendar } from '@/components/ui/calendar'; import TimeSelect from './timeSelect'; import { CalendarEventExternal } from '@schedule-x/calendar'; -import { Textarea } from './ui/textarea'; -import { Label } from './ui/label'; +import { Textarea } from '@/components/ui/textarea'; +import { Label } from '@/components/ui/label'; import { useState } from 'react'; import axios from 'axios'; import { Schedule } from '@/utils'; diff --git a/src/components/timeSelect.tsx b/src/app/calendar/timeSelect.tsx similarity index 100% rename from src/components/timeSelect.tsx rename to src/app/calendar/timeSelect.tsx diff --git a/src/components/accountStatus.tsx b/src/app/dashboard/accountStatus.tsx similarity index 92% rename from src/components/accountStatus.tsx rename to src/app/dashboard/accountStatus.tsx index c1d08dd..8e65d3e 100644 --- a/src/components/accountStatus.tsx +++ b/src/app/dashboard/accountStatus.tsx @@ -1,8 +1,8 @@ 'use client'; import { PlatformKind } from '@/utils'; -import { Card, CardContent, CardHeader, CardTitle } from './ui/card'; -import { PlatformIcon } from './icons'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { PlatformIcon } from '@/components/icons'; export default function AccountStatus({ accounts, diff --git a/src/components/engagement.tsx b/src/app/dashboard/engagement.tsx similarity index 100% rename from src/components/engagement.tsx rename to src/app/dashboard/engagement.tsx diff --git a/src/components/ideas.tsx b/src/app/dashboard/ideas.tsx similarity index 88% rename from src/components/ideas.tsx rename to src/app/dashboard/ideas.tsx index 27b1b00..897395d 100644 --- a/src/components/ideas.tsx +++ b/src/app/dashboard/ideas.tsx @@ -1,7 +1,7 @@ 'use client'; -import { Checkbox } from './ui/checkbox'; -import { Card, CardContent, CardHeader, CardTitle } from './ui/card'; +import { Checkbox } from '@/components/ui/checkbox'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; export default function Ideas({ ideas, diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 7776513..c82586a 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -1,7 +1,7 @@ -import AccountStatus from '@/components/accountStatus'; -import Engagement from '@/components/engagement'; -import Ideas from '@/components/ideas'; -import RecentPosts from '@/components/recentPosts'; +import AccountStatus from './accountStatus'; +import Engagement from './engagement'; +import Ideas from './ideas'; +import RecentPosts from './recentPosts'; import App from '@/components/app'; import { Calendar } from '@/components/ui/calendar'; import { cookies } from 'next/headers'; @@ -12,7 +12,7 @@ async function getSession(sessionId: string) { try { return ( await axios.get(`http:/localhost:3000/api/session/?id=${sessionId}`) - ).data; + ).data.dashboard; } catch { redirect('/login'); } diff --git a/src/components/recentPosts.tsx b/src/app/dashboard/recentPosts.tsx similarity index 93% rename from src/components/recentPosts.tsx rename to src/app/dashboard/recentPosts.tsx index eaebc70..fc3fb2d 100644 --- a/src/components/recentPosts.tsx +++ b/src/app/dashboard/recentPosts.tsx @@ -1,6 +1,6 @@ import { PlatformKind } from '@/utils'; -import { Card, CardContent, CardHeader, CardTitle } from './ui/card'; -import { PlatformIcon } from './icons'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { PlatformIcon } from '@/components/icons'; import { format } from 'date-fns'; export default function RecentPosts({ diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index d9d8df4..4794b2d 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -16,30 +16,27 @@ export default function Login() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); - const handleLogin = () => { - async () => { - try { - const { sessionId } = ( - await axios.post('/api/session/', { - email, - password, - }) - ).data; + const handleLogin = async () => { + try { + const { sessionId } = ( + await axios.post('/api/session/', { + email, + password, + }) + ).data; - cookies.set('session_id', sessionId); + cookies.set('session_id', sessionId); - router.replace('/dashboard'); - } catch (err: any) { - toast({ - title: 'Uh oh! Something went wrong.', - description: err.response - ? err.response.data.message - : String(err), - }); - } - }; + router.replace('/dashboard'); + } catch (err: any) { + toast({ + title: 'Uh oh! Something went wrong.', + description: err.response + ? err.response.data.message + : String(err), + }); + } }; - return (
@@ -60,7 +57,11 @@ export default function Login() { type="password" placeholder="Your password" onChange={(event) => setPassword(event.target.value)} - onClick={handleLogin} + onKeyDown={async (e) => { + if (e.key === 'Enter') { + await handleLogin(); + } + }} />