Skip to content

Commit

Permalink
feat: changed sign up to sign-up and login to sign-in and logout to s…
Browse files Browse the repository at this point in the history
…ign out
  • Loading branch information
wreshi committed Nov 10, 2024
1 parent 8676b7d commit 983cf70
Show file tree
Hide file tree
Showing 34 changed files with 157 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Form,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { loginSchema } from "@/schemas/auth.schema";
import { signInSchema } from "@/schemas/auth.schema";
import { cn } from "@/lib/utils/tailwind";

Check warning on line 13 in src/app/(auth_routes)/sign-in/_components/SignInForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused import { cn } from "@/lib/utils/tailwind";
import { zodResolver } from "@hookform/resolvers/zod";
import { Loader } from "lucide-react";
Expand All @@ -23,25 +23,23 @@ import { z } from "zod";
import { toast } from "sonner";
import { PasswordField } from "@/components/ui/password-input";
import { useRouter } from "@/hooks/use-performance-router";

Check warning on line 25 in src/app/(auth_routes)/sign-in/_components/SignInForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused ``` import { useRouter } from "@/hooks/use-performance-router"; ```
import { signInAction } from "@/server/sign-in";
import { Logo } from "@/components/Logo";

export const LoginForm = ({
login,
}: {
login: (formData: z.infer<typeof loginSchema>) => Promise<any>;
}) => {
const { execute } = useServerAction(login);
export const SignInForm = () => {
const { execute } = useServerAction(signInAction);
const [isSubmitting, setIsSubmitting] = useState(false);

const form = useForm<z.infer<typeof loginSchema>>({
resolver: zodResolver(loginSchema),
const form = useForm<z.infer<typeof signInSchema>>({
resolver: zodResolver(signInSchema),
defaultValues: {
email: "",
password: "",
},
});
const { handleSubmit, control, reset } = form;

const onSubmit = async (formData: z.infer<typeof loginSchema>) => {
const onSubmit = async (formData: z.infer<typeof signInSchema>) => {
setIsSubmitting(true);
const [data, err] = await execute(formData);

Check warning on line 44 in src/app/(auth_routes)/sign-in/_components/SignInForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant data

Expand All @@ -59,7 +57,7 @@ export const LoginForm = ({
return (
<main className="grid h-screen items-center">
{/* <Link
href="/signup"
href="/sign-up"
className={cn(
buttonVariants({ variant: "outline" }),
"absolute right-4 top-4 md:right-8 md:top-8",
Expand All @@ -71,16 +69,11 @@ export const LoginForm = ({
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
<div className="flex flex-col space-y-2 text-center">
<h1 className="flex flex-row items-center justify-center gap-2 text-2xl font-semibold tracking-tight">
<Image
src={"/assets/logo_app.svg"}
alt="Logo"
width={25}
height={25}
/>
Login to Asend
<Logo className="h-6 w-6" />
Sign In to Asend
</h1>
<p className="text-sm text-muted-foreground">
Enter your email and password below to login.
Enter your email and password below to sign in.
</p>
</div>
<div className="flex flex-col gap-4">
Expand Down Expand Up @@ -139,7 +132,7 @@ export const LoginForm = ({
{isSubmitting && (
<Loader className="mr-2 size-4 animate-spin" />
)}
Login
Sign In
</Button>
</form>
</Form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { LoginForm } from "@/app/login/_components/LoginForm";
import { loginAction } from "@/server/login";
import { SignInForm } from "./_components/SignInForm";

Check failure on line 1 in src/app/(auth_routes)/sign-in/page.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
import { Metadata } from "next";
import { fetchAuthenticatedUser } from "@/lib/session";
import { redirect } from "next/navigation";
import { getUserById } from "@/data-access/users";
import { authenticatedUrl } from "@/constants";

export const metadata: Metadata = {
title: "Login",
title: "Sign In",
};

export default async function LoginPage() {
export default async function SignInPage() {
const user = await fetchAuthenticatedUser();
const dbUser = await getUserById(user?.id || "");
if (dbUser && dbUser.verifiedAt && dbUser.checkoutAt) {
return redirect(authenticatedUrl);
}
return <LoginForm login={loginAction} />;
return <SignInForm />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ import { PasswordField } from "@/components/ui/password-input";
import { useRouter } from "@/hooks/use-performance-router";
import { useServerAction } from "zsa-react";
import { useSearchParams } from "next/navigation";
import { signUpAction } from "@/server/sign-up";
import { Logo } from "@/components/Logo";

export const SignUpForm = ({
signUp,
}: {
signUp: (formData: z.infer<typeof signUpSchema>) => Promise<any>;
}) => {
const { execute, isPending, error } = useServerAction(signUp);
export const SignUpForm = () => {
const { execute, isPending, error } = useServerAction(signUpAction);

Check warning on line 31 in src/app/(auth_routes)/sign-up/_components/SignUpForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant error

Check warning on line 31 in src/app/(auth_routes)/sign-up/_components/SignUpForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant isPending
const [isSubmitting, setIsSubmitting] = useState(false);
const router = useRouter();

Check warning on line 33 in src/app/(auth_routes)/sign-up/_components/SignUpForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant router

Expand All @@ -39,7 +37,7 @@ export const SignUpForm = ({
useEffect(() => {
if (searchParams.get("redirecterror") === "nouser") {
toast.error(
"You need to create an account or login before accessing the checkout page.",
"You need to create an account or sign in before accessing the checkout page.",
);
}
}, [searchParams]);
Expand Down Expand Up @@ -91,24 +89,19 @@ export const SignUpForm = ({
return (
<div className="grid h-screen items-center">
<Link
href="/login"
href="/sign-in"
className={cn(
buttonVariants({ variant: "outline" }),
"absolute right-4 top-4 md:right-8 md:top-8",
)}
>
Login
Sign In
</Link>
<div>
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
<div className="flex flex-col space-y-2 text-center">
<h1 className="flex flex-row items-center justify-center gap-2 text-2xl font-semibold tracking-tight">
<Image
src={"/assets/logo_app.svg"}
alt="Logo"
width={25}
height={25}
/>
<Logo className="h-6 w-6" />
Create a free account
</h1>
<p className="text-sm text-muted-foreground">
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { fetchAuthenticatedUser } from "@/lib/session";
import { redirect } from "next/navigation";
import { getUserById } from "@/data-access/users";
import { authenticatedUrl } from "@/constants";
import { Link } from "next-view-transitions";
import { DemoCheckoutButton } from "./_components/DemoCheckoutButton";

export const metadata: Metadata = {
Expand All @@ -14,7 +13,7 @@ export default async function CheckoutPage() {
const PADDLE_DOMAIN_APPROVED = false;
if (PADDLE_DOMAIN_APPROVED) {
const user = await fetchAuthenticatedUser();
if (!user) return redirect("/signup?redirecterror=nouser");
if (!user) return redirect("/sign-up?redirecterror=nouser");
const dbUser = await getUserById(user.id || "");
if (
dbUser &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { toast } from "sonner";
import { onboardingSchema } from "@/schemas/onboarding.schema";
import { onboardingAction } from "@/server/onboarding";

export const OnboardingForm = ({}: {}) => {
export const OnboardingForm = () => {
const { execute, isPending, error } = useServerAction(onboardingAction);

Check warning on line 23 in src/app/(auth_routes)/sign-up/onboarding/_components/OnboardingForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant error

Check warning on line 23 in src/app/(auth_routes)/sign-up/onboarding/_components/OnboardingForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant isPending
const [isSubmitting, setIsSubmitting] = useState(false);
const [formState, setFormState] = useState<number>(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getUserById } from "@/data-access/users";
import { fetchAuthenticatedUser } from "@/lib/session";
import { redirect } from "next/navigation";
import { authenticatedUrl, unauthenticatedUrl } from "@/constants";
import { OnboardingForm } from "@/app/signup/onboarding/_components/OnboardingForm";
import { OnboardingForm } from "./_components/OnboardingForm";

export const metadata: Metadata = {
title: "Onboarding",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SignUpForm } from "@/app/signup/_components/SignUpForm";
import { signUpAction } from "@/server/signup";
import { SignUpForm } from "./_components/SignUpForm";

Check failure on line 1 in src/app/(auth_routes)/sign-up/page.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
import { Metadata } from "next";
import { fetchAuthenticatedUser } from "@/lib/session";
import { redirect } from "next/navigation";
Expand All @@ -10,11 +9,11 @@ export const metadata: Metadata = {
title: "Sign Up",
};

export default async function LoginPage() {
export default async function SignUpPage() {
const user = await fetchAuthenticatedUser();
const dbUser = await getUserById(user?.id || "");
if (dbUser && dbUser.verifiedAt && dbUser.onboardedAt && dbUser.checkoutAt) {
return redirect(authenticatedUrl);
}
return <SignUpForm signUp={signUpAction} />;
return <SignUpForm />;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ import {
import { REGEXP_ONLY_DIGITS } from "input-otp";
import { ResendVerifyEmailButton } from "./ResendVerifyEmailButton";
import Image from "next/image";

Check warning on line 25 in src/app/(auth_routes)/sign-up/verify-email/_components/VerifyEmailForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused import

Unused import Image from "next/image";
import { verifyEmailAction } from "@/server/verify-email";
import { Logo } from "@/components/Logo";

export const VerifyEmailForm = ({
email,
action,
resendAction,
}: {
email: string;
action: (formData: z.infer<typeof verificationCodeSchema>) => Promise<any>;
resendAction: () => Promise<any>;
}) => {
const { execute, isPending, error } = useServerAction(action);
export const VerifyEmailForm = ({ email }: { email: string }) => {
const { execute, isPending, error } = useServerAction(verifyEmailAction);

Check warning on line 30 in src/app/(auth_routes)/sign-up/verify-email/_components/VerifyEmailForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant isPending

Check warning on line 30 in src/app/(auth_routes)/sign-up/verify-email/_components/VerifyEmailForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant error
const [isSubmitting, setIsSubmitting] = useState(false);

const form = useForm<z.infer<typeof verificationCodeSchema>>({
Expand Down Expand Up @@ -62,12 +56,7 @@ export const VerifyEmailForm = ({
<div className="flex min-h-screen flex-col items-center justify-center space-y-6 px-4 py-8">
<div className="flex flex-col space-y-2 text-center">
<h1 className="flex flex-row items-center justify-center gap-2 text-2xl font-semibold tracking-tight">
<Image
src={"/assets/logo_app.svg"}
alt="Logo"
width={25}
height={25}
/>
<Logo className="h-6 w-6" />
Verify your Email
</h1>
<div className="group mt-2 flex flex-row items-center justify-center gap-2 text-sm text-gray-600">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import React from "react";
import { VerifyEmailForm } from "./_components/VerifyEmailForm";
import { getUserById } from "@/data-access/users";
import { fetchAuthenticatedUser } from "@/lib/session";
import {
resendVerifyEmailAction,
verifyEmailAction,
} from "@/server/verify-email";
import { redirect } from "next/navigation";
import { afterVerifyUrl, unauthenticatedUrl } from "@/constants";

Expand All @@ -23,13 +19,7 @@ const VerifyEmailPage = async () => {
if (dbUser?.verifiedAt) {
return redirect(afterVerifyUrl);
}
return (
<VerifyEmailForm
action={verifyEmailAction}
email={dbUser?.email || ""}
resendAction={resendVerifyEmailAction}
/>
);
return <VerifyEmailForm email={dbUser?.email || ""} />;
};

export default VerifyEmailPage;
3 changes: 2 additions & 1 deletion src/app/app/_components/account_page/cards/DealCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ export function DealCard({ deal }: { deal: DealWithPrimaryContact }) {
} else {
setOpen(false);
setOpenDealId("");

router.refresh();

Check notice on line 428 in src/app/app/_components/account_page/cards/DealCard.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Deprecated symbol used

Deprecated symbol used, consult docs for better alternative
}
} catch (error) {
Expand Down Expand Up @@ -453,8 +454,8 @@ export function DealCard({ deal }: { deal: DealWithPrimaryContact }) {
type="button"
onClick={() => {
setOpen(false);
setOpenDealId("");
form.reset();
router.push("?deal=");
}}
>
Cancel
Expand Down
10 changes: 5 additions & 5 deletions src/app/app/_components/forms/NewContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export function NewContactForm({
addContact,
accountId,
accounts,
runCommandFunction,
runCommandAction,
}: {
addContact?: (newContact: any) => void;
accountId?: string;
accounts?: Account[];
runCommandFunction?: (command: () => void) => void;
runCommandAction?: (command: () => void) => void;
}) {
const [loading, setLoading] = React.useState(false);
const [open, setOpen] = React.useState(false);
Expand Down Expand Up @@ -107,7 +107,7 @@ export function NewContactForm({
`/app/${data.data.account.type + "s"}/${data.data.accountId}?contact=${data.data.id}`,
);
}
if (runCommandFunction) {
if (runCommandAction) {
setOpen(false);
setCommandOpen(false);
router.push(
Expand All @@ -126,7 +126,7 @@ export function NewContactForm({
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogTitle className="sr-only">New Contact Form</DialogTitle>
{runCommandFunction ? (
{runCommandAction ? (
<CommandItem
className="flex gap-2"
onSelect={() => {
Expand Down Expand Up @@ -234,7 +234,7 @@ export function NewContactForm({
setLoading(false);
contactform.reset();
setOpen(false);
if (runCommandFunction) {
if (runCommandAction) {
setCommandOpen(false);
}
}}
Expand Down
10 changes: 5 additions & 5 deletions src/app/app/_components/forms/NewDealForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export function NewDealForm({
accessPoint,

Check warning on line 54 in src/app/app/_components/forms/NewDealForm.tsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused parameter accessPoint
addDeal,
addDealKanban,
runCommandFunction,
runCommandAction,
}: {
accountId?: string;
accessPoint?: "accountPage" | "grid" | "board";
accounts?: Account[];
fullButton?: boolean;
addDeal?: (deal: any) => void;
addDealKanban?: (deal: any) => void;
runCommandFunction?: (command: () => void) => void;
runCommandAction?: (command: () => void) => void;
}) {
const [loading, setLoading] = useState(false);
const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -119,7 +119,7 @@ export function NewDealForm({
);
}

if (runCommandFunction) {
if (runCommandAction) {
setOpen(false);
setCommandOpen(false);
router.push(
Expand All @@ -137,7 +137,7 @@ export function NewDealForm({
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogTitle className="sr-only">New Deal Form</DialogTitle>
{runCommandFunction ? (
{runCommandAction ? (
<CommandItem
className="flex gap-2"
onSelect={() => {
Expand Down Expand Up @@ -286,7 +286,7 @@ export function NewDealForm({
setLoading(false);
dealform.reset();
setOpen(false);
if (runCommandFunction) {
if (runCommandAction) {
setCommandOpen(false);
}
}}
Expand Down
Loading

0 comments on commit 983cf70

Please sign in to comment.