diff --git a/src/app/api/child/create/route.ts b/src/app/api/child/create/route.ts
new file mode 100644
index 0000000..94f1aaa
--- /dev/null
+++ b/src/app/api/child/create/route.ts
@@ -0,0 +1,24 @@
+import { newChildSchema } from '@/lib/validations/child';
+import { getServerAuthSession } from '@/lib/services/auth/config';
+import { NextResponse } from 'next/server';
+import { StatusCodes, getReasonPhrase } from 'http-status-codes';
+import db from '@/db/schema';
+import { children } from '@/db/schema/children';
+
+export async function POST(req: Request) {
+ const session = await getServerAuthSession();
+ if (!session)
+ return NextResponse.json(
+ { error: getReasonPhrase(StatusCodes.UNAUTHORIZED) },
+ { status: StatusCodes.UNAUTHORIZED }
+ );
+ const body = await req.json();
+
+ const { name } = newChildSchema.parse(body);
+
+ const child = await db.insert(children).values({
+ name,
+ });
+
+ return NextResponse.json({ status: 'success', pin: 'fartle' });
+}
diff --git a/src/app/api/child/route.ts b/src/app/api/child/route.ts
index 39c30e4..e30d8b2 100644
--- a/src/app/api/child/route.ts
+++ b/src/app/api/child/route.ts
@@ -1,12 +1,12 @@
import db from '@/db/schema';
import { children } from '@/db/schema/children';
-import { getServerSession } from 'next-auth';
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
import { NextResponse } from 'next/server';
-import authOptions from '@/lib/services/auth/config';
+import { getServerAuthSession } from '@/lib/services/auth/config';
+//TODO: create-t3-app supports app router now
export async function GET(request: Request) {
- const session = await getServerSession(authOptions);
+ const session = await getServerAuthSession();
if (!session)
return NextResponse.json(
{ error: getReasonPhrase(StatusCodes.UNAUTHORIZED) },
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 49d44c4..85bc76b 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -9,6 +9,7 @@ import NextAuthProvider from '@/lib/services/auth/provider';
import { ThemeProvider } from '@/components/theme-provider';
import { cn } from '@/lib/utils';
import TanstackProvider from '@/components/providers/tanstack-provider';
+import { Toaster } from '@/components/ui/toaster';
const font = Sanchez({ subsets: ['latin'], weight: '400' });
@@ -46,6 +47,7 @@ export default function RootLayout({
enableSystem
>
{children}
+
diff --git a/src/components/children/add-child-component.tsx b/src/components/children/add-child-component.tsx
index e4024df..39876cc 100644
--- a/src/components/children/add-child-component.tsx
+++ b/src/components/children/add-child-component.tsx
@@ -12,6 +12,7 @@ import {
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
+import { AddChildForm } from '@/components/forms/add-child-form';
const AddChildComponent = () => {
return (
);
diff --git a/src/components/children/child-select-list.tsx b/src/components/children/child-select-list.tsx
index eac8754..525c055 100644
--- a/src/components/children/child-select-list.tsx
+++ b/src/components/children/child-select-list.tsx
@@ -25,6 +25,8 @@ const ChildSelectList = () => {
return data as ChildModel[];
},
});
+ if (isLoading) return
Loading....
;
+ if (isError) return Error loading
;
return (