Skip to content

Commit

Permalink
refactor: cleanup dead code and some bug fixes (#167)
Browse files Browse the repository at this point in the history
* refactor: remove waitlist router

* feat: remove signup page

* chore: remove allow sigin in

* fix: double redirect

* refactor: progress bar

* chore: remove waitlist env

* chore:

* refactor: remove waitlist table

* feat: add public bucket

* feat: add bucket url

* feat: use bucket url

* feat: use image patterns

* refactor: extract get compnay

* refactor: remove duplicate form

* feat: update form
  • Loading branch information
G3root authored Mar 5, 2024
1 parent ab6121d commit 9072af8
Show file tree
Hide file tree
Showing 28 changed files with 162 additions and 706 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,3 @@ PUBLIC_UPLOAD_BUCKET="opencap-public"
UPLOAD_ACCESS_KEY_ID="opencap"
UPLOAD_SECRET_ACCESS_KEY="password"

# Flags
WAITLIST_MODE="off"
18 changes: 17 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,23 @@ services:
- MINIO_ROOT_USER=opencap
- MINIO_ROOT_PASSWORD=password
entrypoint: sh
command: -c 'mkdir -p /data/opencap && minio server /data --console-address ":9001" --address ":9002"'
command: -c 'minio server /data --console-address ":9001" --address ":9002"'


mc:
image: minio/mc
container_name: opencap-minio-client
entrypoint: >
/bin/sh -c "
/usr/bin/mc config;
/usr/bin/mc config host add myminio http://minio:9002 opencap password;
/usr/bin/mc mb myminio/opencap;
/usr/bin/mc mb myminio/opencap-public;
/usr/bin/mc anonymous set public myminio/opencap-public;
exit 0;
"
depends_on:
- minio

volumes:
minio:
Expand Down
21 changes: 10 additions & 11 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ await import("./src/env.js");
/** @type {import("next").NextConfig} */
const config = {
images: {
domains: ["randomuser.me", "avatars.githubusercontent.com"],
remotePatterns: [
{
hostname: "randomuser.me",
protocol: "https",
},
{
hostname: "avatars.githubusercontent.com",
protocol: "https",
},
],
},
webpack: (config) => {
/**
Expand All @@ -20,16 +29,6 @@ const config = {

return config;
},

async redirects() {
return [
{
source: "/",
destination: "/login",
permanent: true,
},
];
},
};

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the `WaitlistUser` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
DROP TABLE "WaitlistUser";
6 changes: 0 additions & 6 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ model User {
companies Member[]
}

model WaitlistUser {
id String @id @default(cuid())
email String @unique
createdAt DateTime @default(now())
}

model VerificationToken {
identifier String
token String @unique
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import CompanyForm from "@/components/onboarding/company-form";
import { withServerSession } from "@/server/auth";
import { getCompany } from "@/server/company";
import { CompanyForm } from "@/components/onboarding/company-form";
import { api } from "@/trpc/server";

const CompanySettingsPage = async () => {
const session = await withServerSession();
const user = session.user;
const data = await api.company.getCompany.query();

const companyResponse = await getCompany(user.id, user.companyId);

return (
<CompanyForm
companyServerResponse={companyResponse}
formType="edit-company"
currentUser={user}
/>
);
return <CompanyForm data={data} type="edit" />;
};

export default CompanySettingsPage;
8 changes: 2 additions & 6 deletions src/app/(authenticated)/(dashboard)/company/new/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Navbar } from "@/components/navbar";
import CompanyForm from "@/components/onboarding/company-form";
import { withServerSession } from "@/server/auth";
import { CompanyForm } from "@/components/onboarding/company-form";

const OnboardingPage = async () => {
const session = await withServerSession();
const user = session.user;

return (
<div className="flex min-h-screen justify-center bg-gradient-to-br from-indigo-50 via-white to-cyan-100 px-5 pb-5 pt-20">
<Navbar />
Expand All @@ -19,7 +15,7 @@ const OnboardingPage = async () => {
You are almost there. Please complete the form below to continue
</p>
</div>
<CompanyForm formType="create-company" currentUser={user} />
<CompanyForm type="create" />
</div>
</div>
);
Expand Down
8 changes: 3 additions & 5 deletions src/app/(authenticated)/onboarding/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Navbar } from "@/components/navbar";
import CompanyForm from "@/components/onboarding/company-form";
import { CompanyForm } from "@/components/onboarding/company-form";
import { withServerSession } from "@/server/auth";
import { redirect } from "next/navigation";

const OnboardingPage = async () => {
const session = await withServerSession();
const user = session.user;
console.log({
user,
});

if (user.isOnboarded) {
redirect("/dashboard");
}
Expand All @@ -26,7 +24,7 @@ const OnboardingPage = async () => {
You are almost there. Please complete the form below to continue
</p>
</div>
<CompanyForm formType="onboarding" currentUser={user} />
<CompanyForm type="onboarding" />
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { cn } from "@/lib/utils";
import { cookies } from "next/headers";
import { TRPCReactProvider } from "@/trpc/react";
import { type Metadata } from "next";
import ProgressBarProvider from "./providers/progress-bar";
import { constants } from "@/lib/constants";
import { Toaster } from "@/components/ui/toaster";
import { NextAuthProvider } from "@/providers/next-auth";
import { getServerAuthSession } from "@/server/auth";
import { ProgressBarProvider } from "@/providers/progress-bar";

export const metadata: Metadata = {
title: "OpenCap",
Expand Down
5 changes: 2 additions & 3 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { redirect } from "next/navigation";
import LoginForm from "@/components/onboarding/login";
import { authOptions } from "@/server/auth";
import { getServerSession } from "next-auth";
import { getServerAuthSession } from "@/server/auth";

import type { Metadata } from "next";
import { IS_GOOGLE_AUTH_ENABLED } from "@/constants/auth";
Expand All @@ -12,7 +11,7 @@ export const metadata: Metadata = {
};

export default async function AuthPage() {
const session = await getServerSession(authOptions);
const session = await getServerAuthSession();

if (session?.user?.companyPublicId) {
return redirect(`/${session.user.companyPublicId}`);
Expand Down
12 changes: 12 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getServerAuthSession } from "@/server/auth";
import { redirect } from "next/navigation";

export default async function HomePage() {
const session = await getServerAuthSession();

if (session?.user?.companyPublicId) {
return redirect(`/${session.user.companyPublicId}`);
}

return redirect("/login");
}
19 changes: 0 additions & 19 deletions src/app/signup/page.tsx

This file was deleted.

4 changes: 3 additions & 1 deletion src/common/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const uploadFile = async (
>,
bucketMode: "publicBucket" | "privateBucket" = "privateBucket",
) => {
const { url, key } = await getPresignedPutUrl({
const { url, key, bucketUrl } = await getPresignedPutUrl({
contentType: file.type,
fileName: file.name,
bucketMode,
Expand All @@ -44,12 +44,14 @@ export const uploadFile = async (
`Failed to upload file "${file.name}", failed with status code ${res.status}`,
);
}

const { name, type, size } = file;
return {
key,
name,
mimeType: type,
size,
bucketUrl,
};
};

Expand Down
13 changes: 4 additions & 9 deletions src/components/member/member-profile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @next/next/no-img-element */
"use client";

import Image from "next/image";
import { useForm } from "react-hook-form";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
Expand All @@ -12,7 +12,6 @@ import React, { useRef } from "react";
import { useToast } from "@/components/ui/use-toast";
import { useSession } from "next-auth/react";
import { uploadFile } from "@/common/uploads";
import { env } from "@/env";
import { useRouter } from "next/navigation";
import {
compareFormDataWithInitial,
Expand Down Expand Up @@ -121,13 +120,9 @@ export const ProfileSettings = ({ memberProfile }: ProfileType) => {
keyPrefix: "profile-avatars",
identifier: session.user.id,
};
const { key } = await uploadFile(file, options, "publicBucket");
const { bucketUrl } = await uploadFile(file, options, "publicBucket");

const s3BaseURL = `https://${env.PUBLIC_UPLOAD_BUCKET}.s3.amazonaws.com`;

const imageUrl = `${s3BaseURL}/${key}`;

return { imageUrl };
return { imageUrl: bucketUrl };
}

return { imageUrl: "" };
Expand Down Expand Up @@ -218,7 +213,7 @@ export const ProfileSettings = ({ memberProfile }: ProfileType) => {
<form onSubmit={form.handleSubmit(onSubmit)}>
<div className="grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-6">
<div className="col-span-full flex items-center gap-x-8">
<Image
<img
src={session?.user.image ?? "/avatar.svg"}
alt="User avatar"
width={50}
Expand Down
Loading

0 comments on commit 9072af8

Please sign in to comment.