-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dropzone, multiple upload, redisign
- Loading branch information
Showing
11 changed files
with
3,098 additions
and
200 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use client"; | ||
import React, { FormEvent, useState } from "react"; | ||
|
||
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
const formData = new FormData(e.currentTarget); | ||
|
||
const response = await fetch("/api/admin", { | ||
method: "POST", | ||
body: formData, | ||
}); | ||
|
||
const data = await response.json(); | ||
console.log({ data }); | ||
|
||
if (response.ok) { | ||
window.location.href = "/admin"; | ||
} else { | ||
alert(data.error); | ||
} | ||
}; | ||
|
||
export const Form = () => { | ||
const [showPassword, setShowPassword] = useState(false); | ||
|
||
return ( | ||
<form | ||
className="flex flex-col gap-4 w-full max-w-md" | ||
onSubmit={handleSubmit} | ||
> | ||
<label className="flex flex-col" htmlFor="login"> | ||
Login | ||
<input | ||
className="border border-gray-500 rounded px-2 py-1" | ||
type="text" | ||
id="login" | ||
name="login" | ||
/> | ||
</label> | ||
|
||
<label className="flex flex-col" htmlFor="password"> | ||
Password | ||
<div className="relative"> | ||
<input | ||
className="border border-gray-500 rounded px-2 py-1 pr-10 w-full" | ||
type={showPassword ? "text" : "password"} | ||
id="password" | ||
name="password" | ||
/> | ||
|
||
<button | ||
type="button" | ||
className="absolute inset-y-0 right-0 flex items-center pr-3" | ||
onClick={() => setShowPassword(!showPassword)} | ||
> | ||
{showPassword ? "🙈" : "👁️"} | ||
</button> | ||
</div> | ||
</label> | ||
|
||
<button | ||
className="bg-blue-500 text-white px-4 py-2 rounded" | ||
type="submit" | ||
> | ||
Log in | ||
</button> | ||
</form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Rubik } from "next/font/google"; | ||
import clsx from "clsx"; | ||
import { Form } from "./Form"; | ||
|
||
const rubik = Rubik({ | ||
variable: "--font-rubik", | ||
subsets: ["latin"], | ||
}); | ||
|
||
export default async function AdminPage() { | ||
return ( | ||
<main className="container mx-auto py-8 px-4 h-dvh flex w-full flex-col items-center text-black"> | ||
<h1 className={clsx("text-3xl mb-4", rubik.variable)}>Admin</h1> | ||
|
||
<Form /> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { cookies } from "next/headers"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import jwt from "jsonwebtoken"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const cookieStore = await cookies(); | ||
const data = await request.formData(); | ||
console.log(data); | ||
const login = data.get("login") as string; | ||
const password = data.get("password") as string; | ||
|
||
if ( | ||
login === process.env.NEXT_ADMIN_LOGIN && | ||
password === process.env.NEXT_ADMIN_PASSWORD | ||
) { | ||
const token = jwt.sign({ role: "admin" }, process.env.NEXT_JWT_SECRET_KEY!); | ||
|
||
cookieStore.set("admin", token, { | ||
name: "admin", | ||
maxAge: 60 * 60 * 24 * 1, | ||
sameSite: "strict", | ||
path: "/", | ||
}); | ||
|
||
return NextResponse.json({ success: true }); | ||
} | ||
|
||
return NextResponse.json( | ||
{ success: false, error: "wrong login or password" }, | ||
{ status: 401 } | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.