Skip to content

Commit

Permalink
Merge pull request #1 from High-Country-Dev/refactor/auth-and-mongoos…
Browse files Browse the repository at this point in the history
…e-md-5012

[MD-5012] refactor: updated middleware, auth, db conn etc.
  • Loading branch information
tonpascual authored Oct 22, 2024
2 parents 4edba6c + aef7841 commit 3d2a824
Show file tree
Hide file tree
Showing 38 changed files with 1,386 additions and 233 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
5 changes: 3 additions & 2 deletions apps/isomorphic-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@react-email/section": "0.0.12",
"@react-email/tailwind": "0.0.16",
"@react-email/text": "0.0.8",
"@repo/nosql": "workspace:*",
"@t3-oss/env-nextjs": "^0.10.1",
"@tailwindcss/container-queries": "^0.1.1",
"@tanstack/react-query": "^5.59.9",
Expand All @@ -51,6 +52,7 @@
"@trpc/server": "11.0.0-next-beta.264",
"@uploadthing/react": "^6.5.1",
"accept-language": "^3.0.18",
"bcryptjs": "^2.4.3",
"clsx": "^2.1.1",
"d3-dsv": "^3.0.1",
"date-arithmetic": "^4.1.0",
Expand All @@ -69,8 +71,6 @@
"lodash": "^4.17.21",
"mapbox-gl": "^3.5.2",
"maplibre-gl": "^4.5.0",
"mongodb": "^6.8.0",
"mongoose": "^8.5.1",
"next": "14.2.3",
"next-auth": "^4.24.7",
"next-themes": "^0.3.0",
Expand Down Expand Up @@ -129,6 +129,7 @@
"@repo/typescript-config": "workspace:*",
"@tailwindcss/forms": "^0.5.7",
"@total-typescript/ts-reset": "^0.5.1",
"@types/bcryptjs": "^2.4.6",
"@types/date-arithmetic": "^4.1.4",
"@types/google.maps": "^3.55.8",
"@types/js-cookie": "^3.0.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function NewPage({
<div className="mb-6 grid grid-cols-1 gap-6 @4xl:grid-cols-12 2xl:mb-8 2xl:gap-8">
<AggregatedCatch
className="@container @4xl:col-span-8 @[96.937rem]:col-span-9"
lang={lang}
//lang={lang}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default function AIAPage() {
return (
<div>
AIA
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default function CIAPage() {
return (
<div>
CIA
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default function ControlPage() {
return (
<div>
Control
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default function IIAPage() {
return (
<div>
IIA
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default function WBCIAPage() {
return (
<div>
CIA
</div>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SignInForm from '@/app/[lang]/signin/sign-in-form';
import AuthWrapperOne from '@/app/shared/auth-layout/auth-wrapper-one';
import Image from 'next/image';

import SignInForm from '@/app/[lang]/sign-in/sign-in-form';
import AuthWrapperOne from '@/app/shared/auth-layout/auth-wrapper-one';
import UnderlineShape from '@components/shape/underline';
import { metaObject } from '@/config/site.config';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
'use client';

import Link from 'next/link';
import { useState } from 'react';
import { useState, Fragment } from 'react';
import { signIn } from 'next-auth/react';
import { SubmitHandler } from 'react-hook-form';
import { PiArrowRightBold } from 'react-icons/pi';
import { Checkbox, Password, Button, Input, Text } from 'rizzui';
import { Checkbox, Password, Button, Input, Text, Loader } from 'rizzui';
import { useRouter } from 'next/navigation'

import { Form } from '@ui/form';
import { routes } from '@/config/routes';
import { loginSchema, LoginSchema } from '@/validators/login.schema';
import Alert from '@/app/_components/alert';

const initialValues: LoginSchema = {
email: 'admin@admin.com',
password: 'admin',
email: 'anthony@mountaindev.com',
password: '1234qwer',
rememberMe: true,
};

export default function SignInForm() {
//TODO: why we need to reset it here
const [reset, setReset] = useState({});
const [loading, setLoading] = useState(false)
const [loginErr, setLoginErr] = useState('')
const [reset, setReset] = useState({})
const router = useRouter()

const onSubmit: SubmitHandler<LoginSchema> = (data) => {
console.log(data);
signIn('credentials', {
const onSubmit: SubmitHandler<LoginSchema> = async (data) => {
setLoading(true)
setLoginErr('')
const resp = await signIn('credentials', {
...data,
});
redirect: false
})

if (resp?.ok) {
router.push('/')
} else if (!resp?.ok && resp?.error) {
setLoginErr(resp?.error)
}
setLoading(false)
};

return (
Expand All @@ -39,6 +54,7 @@ export default function SignInForm() {
>
{({ register, formState: { errors } }) => (
<div className="space-y-5">
{loginErr && <Alert color="danger" message={loginErr} className="mb-[16px]" />}
<Input
type="email"
size="lg"
Expand Down Expand Up @@ -72,8 +88,11 @@ export default function SignInForm() {
</Link>
</div>
<Button className="w-full" type="submit" size="lg">
<span>Sign in</span>{' '}
<PiArrowRightBold className="ms-2 mt-0.5 h-5 w-5" />
{loading
? <Loader variant="spinner" color="current"/>
: <Fragment><span>Sign in</span>{' '}<PiArrowRightBold className="ms-2 mt-0.5 h-5 w-5" /></Fragment>
}

</Button>
</div>
)}
Expand Down
23 changes: 23 additions & 0 deletions apps/isomorphic-i18n/src/app/_components/alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Alert as RAlert, Text } from "rizzui"

import cn from "@utils/class-names";

export default function Alert({
color,
message,
className,
}: {
color: 'danger' | 'success' | 'warning';
message: string;
className?: string;
}) {
return (
<RAlert
color={color}
variant="flat"
className={cn(className)}
>
<Text>{message}</Text>
</RAlert>
)
}
97 changes: 48 additions & 49 deletions apps/isomorphic-i18n/src/app/api/aggregated-catch/route.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
import { NextRequest, NextResponse } from "next/server";
import clientPromise from "@/app/mongodb";
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest) {
try {
const client = await clientPromise;
const db = client.db("kenya");
const collection = db.collection("legacy_data");
/**
* TODO: migrate to mongoose
*/

// Filter and aggregate data
const data = await collection
.aggregate([
{
$match: {
landing_site: "Kenyatta",
},
},
{
$project: {
landing_date: {
$dateTrunc: {
date: "$landing_date",
unit: "month",
},
},
fish_category: 1,
catch_kg: 1,
},
},
{
$group: {
_id: {
landing_date: "$landing_date",
fish_category: "$fish_category",
},
catch_kg: { $sum: "$catch_kg" },
},
},
{
$sort: { "_id.landing_date": 1, "_id.fish_category": 1 },
},
])
.toArray();
export async function GET(req: NextRequest) {
// try {
// const client = await clientPromise;
// const db = client.db('kenya');
// const collection = db.collection('legacy_data');

// // Filter and aggregate data
// const data = await collection.aggregate([
// {
// $match: {
// landing_site: "Kenyatta"
// }
// },
// {
// $project: {
// landing_date: {
// $dateTrunc: {
// date: "$landing_date",
// unit: "month"
// }
// },
// fish_category: 1,
// catch_kg: 1
// }
// },
// {
// $group: {
// _id: {
// landing_date: "$landing_date",
// fish_category: "$fish_category"
// },
// catch_kg: { $sum: "$catch_kg" }
// }
// },
// {
// $sort: { "_id.landing_date": 1, "_id.fish_category": 1 }
// }
// ]).toArray();

return NextResponse.json(data);
} catch (error) {
console.error("Error fetching data:", (error as Error).message);
return NextResponse.json(
{ error: "Internal Server Error", details: (error as Error).message },
{ status: 500 }
);
}
// return NextResponse.json(data);
// } catch (error) {
// console.error('Error fetching data:', (error as Error).message);
// return NextResponse.json({ error: 'Internal Server Error', details: (error as Error).message }, { status: 500 });
// }
return NextResponse.json({});
}
Loading

0 comments on commit 3d2a824

Please sign in to comment.