Skip to content

Commit

Permalink
first upload
Browse files Browse the repository at this point in the history
  • Loading branch information
oopshwet authored Oct 20, 2024
0 parents commit 6e6abc6
Show file tree
Hide file tree
Showing 42 changed files with 8,360 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
52 changes: 52 additions & 0 deletions app/components/header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use client";

import Image from "next/image";
import Icon from "../../public/logo/logo-transparent-svg.svg";
import Link from "next/link";
import { useRouter } from "next/navigation";
import {AppwriteConfig} from "../constants/appwrite_config";

export default function Header() {
const appwriteConfig = new AppwriteConfig();
const router = useRouter();
return (
<header className="text-gray-400 bg-white body-font">
<div className="container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center">
<Link href="/landing">
<Image src={Icon} height={200} width={200} alt="Product Logo" />
</Link>
<nav className="md:ml-auto flex flex-wrap items-center text-base justify-center">
<Link
className="mr-5 hover:text-gray-900 text-gray-500 "
href="/myevents"
>
My Events
</Link>
<Link
className="mr-5 hover:text-gray-900 text-gray-500 "
href="/events"
>
Find Events
</Link>
<Link className="mr-5 hover:text-gray-900 text-gray-500 " href="/create">
Create Event
</Link>
</nav>
<button
className="inline-flex items-center bg-[#f02e65] border-0 py-1 px-3 focus:outline-none hover:bg-[#ab073d] rounded-full text-base mt-4 md:mt-0"
onClick={() => {
const sucess = appwriteConfig.signOut(
JSON.parse(localStorage.getItem("userInfo") || "{}")["$id"]
);
if (sucess) {
localStorage.removeItem("userInfo");
router.push("/login");
}
}}
>
<p className="text-sm my-1 text-white">Sign Out</p>
</button>
</div>
</header>
);
}
233 changes: 233 additions & 0 deletions app/constants/appwrite_config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
"use client";

import { Client, Account, Models, ID, Databases, Storage } from "appwrite";
import { User } from "./interface";
import sdk, { Permission, Role } from "node-appwrite";

interface Sponsors {
id: number;
name: string;
url: string;
}
class ServerConfig {
client: sdk.Client = new sdk.Client();
regDb: string = `${process.env.NEXT_PUBLIC_REGDB}`;
sponDb: string = `${process.env.NEXT_PUBLIC_SPODB}`;
databases: sdk.Databases = new sdk.Databases(this.client);

constructor() {
this.client
.setEndpoint(`${process.env.NEXT_PUBLIC_ENDPOINT}`)
.setProject(`${process.env.NEXT_PUBLIC_PROJECTID}`)
.setKey(`${process.env.NEXT_PUBLIC_DBKEY}`);
}

createRegColl(id: string, name: string) {
this.databases
.createCollection(this.regDb, id, name, [
Permission.read(Role.any()), // Anyone can view this document
Permission.update(Role.any()), // Writers can update this document
Permission.create(Role.any()), // Admins can update this document
Permission.delete(Role.any()), // Admins can delete this document
])
.then((res) => {
this.databases.createStringAttribute(this.regDb, id, "name", 50, false);
this.databases.createStringAttribute(this.regDb, id, "email", 50, false);
this.databases.createStringAttribute(this.regDb, id, "confirm", 50, false, "");

});
}

createSponColl(id: string, name: string, sponsor: Sponsors[], user:string) {
this.databases
.createCollection(this.sponDb, id, name, [
Permission.read(Role.any()), // Anyone can view this document
Permission.update(Role.user(user)), // Writers can update this document
Permission.create(Role.user(user)), // Admins can update this document
Permission.delete(Role.user(user)), // Admins can delete this document
])
.then((res) => {
this.databases
.createStringAttribute(this.sponDb, id, "name", 50, false)
.then((res) => {
this.databases
.createStringAttribute(this.sponDb, id, "url", 50, false)
.then((res) => {
for (var i = 0; i < sponsor.length; i++) {
this.databases.createDocument(this.sponDb, id, ID.unique(), {
name: sponsor[i].name,
url: sponsor[i].url,
});
}
});
});
});
}
}

class AppwriteConfig {
databaseId: string = `${process.env.NEXT_PUBLIC_DATABASEID}`;
activeCollId: string = `${process.env.NEXT_PUBLIC_EVENT_COLLID}`;
bannerBucketId: string = `${process.env.NEXT_PUBLIC_EVENTBUCKET}`;
regDbId: string = `${process.env.NEXT_PUBLIC_REGDB}`;

client: Client = new Client();
account: Account = new Account(this.client);
databases: Databases = new Databases(this.client);
regDb: Databases = new Databases(this.client);
storage: Storage = new Storage(this.client);
user: User = {} as User;

constructor() {
this.client
.setEndpoint(`${process.env.NEXT_PUBLIC_ENDPOINT}`)
.setProject(`${process.env.NEXT_PUBLIC_PROJECTID}`);
}

googlelog(): void {
try {
const promise = this.account.createOAuth2Session(
"google",
`${process.env.NEXT_PUBLIC_APPURL}/login/sucess`,
`${process.env.NEXT_PUBLIC_APPURL}/login/failure`,
[]
);
this.getCurUser();
} catch (error) {
console.log(error);
}
}

githublog(): void {
try {
this.account.createOAuth2Session(
"github",
`${process.env.NEXT_PUBLIC_APPURL}/login/sucess`,
`${process.env.NEXT_PUBLIC_APPURL}/login/failure`,
[]
);
this.getCurUser();
} catch (error) {
console.log(error);
}
}

getCurUser(): void {
try {
this.account
.get()
.then((res) => {
this.user = res;
localStorage.setItem("userInfo", JSON.stringify(this.user));
})
.catch((err) => {
console.log(err);
});
} catch (error) {
console.log(error);
}
}

emailSignUp(name: string, email: string, password: string): void {
try {
this.account.create(ID.unique(), email, password, name);
} catch (error) {
console.log(error);
}
}

emailLogin(email: string, password: string): Promise<Models.Session> {
return this.account.createEmailSession(email, password);
}

signOut(id: string): boolean {
try {
this.account.deleteSession(id);
return true;
} catch (error) {
console.log(error);
return false;
}
}

magicUrlLogin(email: string): void {
this.account.createMagicURLSession(
ID.unique(),
email,
`${process.env.NEXT_PUBLIC_APPURL}/login/sucess`
);
this.getCurUser();
}

createEvent(
eventname: string,
description: string,
banner: File,
hostname: string,
eventdate: string,
email: string,
country: string,
address: string,
city: string,
state: string,
postal: string,
audience: string,
type: string,
attendees: number,
price: number,
tech: string,
agenda: string,
sponsor: Sponsors[],
approval: string,
twitter: string,
website: string,
linkedin: string,
instagram: string
): Promise<String> {
try {
this.storage
.createFile(this.bannerBucketId, ID.unique(), banner)
.then((res) => {
this.databases
.createDocument(this.databaseId, this.activeCollId, ID.unique(), {
eventname: eventname,
description: description,
url: `${process.env.NEXT_PUBLIC_ENDPOINT}/storage/buckets/${this.bannerBucketId}/files/${res.$id}/view?project=${process.env.NEXT_PUBLIC_PROJECTID}&mode=admin`,
hostname: hostname,
eventdate: eventdate,
email: email,
country: country,
address: address,
city: city,
state: state,
postal: postal,
audience: audience,
type: type,
attendees: attendees,
price: price,
tech: tech,
agenda: agenda,
approval: approval,
created: JSON.parse(localStorage.getItem("userInfo") || "{}").$id,
twitter: twitter,
website: website,
linkedin: linkedin,
instagram: instagram,
registrations: [],
})
.then((res) => {
const serverConfig = new ServerConfig();
serverConfig.createRegColl(res.$id, eventname);
serverConfig.createSponColl(res.$id, eventname, sponsor, JSON.parse(localStorage.getItem("userInfo") || "{}").$id);
return Promise.resolve("sucess");
});
});
} catch (error) {
console.log("error block 1");
throw error;
}
return Promise.resolve("sucess");
}
}

export {AppwriteConfig, ServerConfig};
26 changes: 26 additions & 0 deletions app/constants/interface.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export interface User {
$id: string;
$createdAt: string;
$updatedAt: string;
name: string;
password?: string | undefined;
hash?: string | undefined;
hashOptions?: object | undefined;
registration: string;
status: boolean;
passwordUpdate: string;
email: string;
phone: string;
emailVerification: boolean;
phoneVerification: boolean;
prefs: Prefs;
}

export interface HashOptions {
type: string;
memoryCost: number;
timeCost: number;
threads: number;
}

export interface Prefs {}
Loading

0 comments on commit 6e6abc6

Please sign in to comment.