refactor: migrate authentication and signup flow to use external API and improve type safety
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m58s

This commit is contained in:
2025-01-24 11:42:38 +05:00
parent 8ffabb1fcb
commit 0fd269df31
9 changed files with 96 additions and 73 deletions

View File

@ -5,7 +5,6 @@ import Link from "next/link";
import { signup } from "@/actions/auth-actions";
import { cn } from "@/lib/utils";
import type { Island, Prisma } from "@prisma/client";
import { Loader2 } from "lucide-react";
import { useSearchParams } from "next/navigation";
import * as React from "react";
@ -19,16 +18,11 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import type { Atoll } from "@/lib/backend-types";
type AtollWithIslands = Prisma.AtollGetPayload<{
include: {
islands: true;
};
}>;
export default function SignUpForm({ atolls }: { atolls: AtollWithIslands[] }) {
const [atoll, setAtoll] = React.useState<AtollWithIslands>();
const [islands, setIslands] = React.useState<Island[]>();
export default function SignUpForm({ atolls }: { atolls: Atoll[] }) {
const [atoll, setAtoll] = React.useState<Atoll>();
const [actionState, action, isPending] = React.useActionState(signup, {
message: "",
@ -36,7 +30,7 @@ export default function SignUpForm({ atolls }: { atolls: AtollWithIslands[] }) {
React.useEffect(() => {
setIslands(atoll?.islands);
console.log(atoll)
}, [atoll]);
@ -122,11 +116,11 @@ export default function SignUpForm({ atolls }: { atolls: AtollWithIslands[] }) {
<Select
disabled={isPending}
onValueChange={(v) => {
setAtoll(atolls.find((atoll) => atoll.id === v));
setIslands([]);
console.log({ v })
setAtoll(atolls.find((atoll) => atoll.id === Number.parseInt(v)));
}}
name="atoll_id"
value={atoll?.id}
value={atoll?.id?.toString() ?? ""}
>
<SelectTrigger className="w-full">
<SelectValue placeholder="Select atoll" />
@ -135,7 +129,7 @@ export default function SignUpForm({ atolls }: { atolls: AtollWithIslands[] }) {
<SelectGroup>
<SelectLabel>Atolls</SelectLabel>
{atolls.map((atoll) => (
<SelectItem key={atoll.id} value={atoll.id}>
<SelectItem key={atoll.id} value={atoll.id.toString()}>
{atoll.name}
</SelectItem>
))}
@ -159,8 +153,8 @@ export default function SignUpForm({ atolls }: { atolls: AtollWithIslands[] }) {
<SelectContent>
<SelectGroup>
<SelectLabel>Islands</SelectLabel>
{islands?.map((island) => (
<SelectItem key={island.id} value={island.id}>
{atoll?.islands?.map((island) => (
<SelectItem key={island.id} value={island.id.toString()}>
{island.name}
</SelectItem>
))}
@ -333,4 +327,4 @@ export default function SignUpForm({ atolls }: { atolls: AtollWithIslands[] }) {
</div>
</form>
);
}
}