Skip to content

Commit

Permalink
Autorize done, style and i/o done
Browse files Browse the repository at this point in the history
  • Loading branch information
Martial-Geek committed Sep 2, 2023
1 parent 6eb2c83 commit 949e32f
Show file tree
Hide file tree
Showing 24 changed files with 1,156 additions and 166 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MONGODB_URI=mongodb+srv://admin-uwais:password%[email protected]/?retryWrites=true&w=majority
30 changes: 30 additions & 0 deletions app/api/signin/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import User from "../../../models/user.js";
import { connectToDB } from "@utils/database.js";

export const POST = async (request, res) => {
try {
const requestData = await request.json();
const { email } = requestData;
console.log(email);

await connectToDB();

const userExists = await User.findOne({ email: email });

if (userExists) {
return new Response(
JSON.stringify({ message: "Successfully signed In" }),
{
status: 201,
}
);
} else {
return new Response(JSON.stringify({ message: "Please Sign Up" }), {
status: 200,
});
}
} catch (error) {
console.error(error);
return new Response("Failed to sign in", { status: 500 });
}
};
37 changes: 37 additions & 0 deletions app/api/submit-form/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import User from "../../../models/user.js";
import { connectToDB } from "@utils/database.js";

export const POST = async (request, res) => {
try {
const requestData = await request.json();
const { name, email, phone } = requestData;
console.log(name, email, phone);

await connectToDB();

const userExists = await User.findOne({ email: email });

if (!userExists) {
await User.create({
name: name,
email: email,
phone: phone,
});

return new Response(JSON.stringify({ message: "User created" }), {
status: 201,
});
} else {
return new Response(JSON.stringify({ message: "User already exists" }), {
status: 200,
});
}

// const newUser = new User({ name, email, phone });
// await newUser.save();
// return new Response(JSON.stringify({ message: "User created" }), { status: 201 });
} catch (error) {
console.error(error);
return new Response("Failed to create a new prompt", { status: 500 });
}
};
Binary file removed app/favicon.ico
Binary file not shown.
27 changes: 0 additions & 27 deletions app/globals.css

This file was deleted.

17 changes: 0 additions & 17 deletions app/layout.js

This file was deleted.

17 changes: 17 additions & 0 deletions app/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "@styles/globals.css";
import Provider from "@components/Provider";

export const metadata = {
title: "Promptopia",
description: "Discover & Share AI Prompts",
};

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<main>{children}</main>
</body>
</html>
);
}
113 changes: 0 additions & 113 deletions app/page.js

This file was deleted.

55 changes: 55 additions & 0 deletions app/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"use client";
import Form from "../components/Form";
import { useState } from "react";
import { useRouter } from "next/navigation";

const Home = () => {
const handleSignUpInputChange = async (e) => {
const { name, value } = e.target;
setFormData((prevData) => ({ ...prevData, [name]: value }));
};

const handleSignUpSubmit = async (e) => {
e.preventDefault();
try {
const response = await fetch("/api/submit-form", {
method: "POST",
body: JSON.stringify({
name: formData.name,
email: formData.email,
phone: formData.phone,
}),
});

if (response.status === 201) {
router.push("/profile");
}
} catch (error) {
console.log(error);
}
};

const [formData, setFormData] = useState({
name: "",
email: "",
phone: "",
});

const router = useRouter();

return (
<section className="w-full flex-center flex-col">
<h1 className="head_text text-center">
Discover & Share
<br className="max-md:hidden" />
<span className="orange_gradient text-center"> AI-Powered Prompts</span>
</h1>
<p className="desc text-center">
Promptopia is an open-source AI prompting tool for modern world to
discover, create and share creative prompts
</p>
<Form onChange={handleSignUpInputChange} onSubmit={handleSignUpSubmit} />
</section>
);
};
export default Home;
12 changes: 12 additions & 0 deletions app/profile/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import Nav from "@components/Navbar";

const Profile = () => {
return (
<div>
<Nav />
</div>
);
};

export default Profile;
Loading

0 comments on commit 949e32f

Please sign in to comment.