Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rushil-b-patel committed May 25, 2024
2 parents c6d3483 + 82c4b55 commit 19138dc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 56 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/category-pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function CategoryPill({ category, disabled, selected = false }: C
return (
<span
className={twMerge(
'cursor-pointer rounded-3xl px-3 py-1 text-xs font-medium text-light-primary/80 dark:text-dark-primary/80 ',
'cursor-pointer rounded-3xl px-3 py-1 text-xs font-medium text-light-primary/80 dark:text-dark-primary/80 overflow-hidden whitespace-nowrap truncate',
disabled ? disabledColor : getSelectedColor(selected)
)}
>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default function PostCard({ post, testId = 'postcard' }: { post: Post } &
<p className="line-clamp-2 text-sm text-light-description dark:text-dark-description">
{post.description}
</p>
<div className="mt-4 flex flex-wrap gap-2">
{post.categories.map((category, index) => (
<div className="mt-4 flex gap-2">
{post.categories.slice(0, 3).map((category, index) => (
<CategoryPill key={`${category}-${index}`} category={category} />
))}
</div>
Expand Down
55 changes: 29 additions & 26 deletions frontend/src/pages/signin-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,51 @@ import { toast } from 'react-toastify';
import { AxiosError, isAxiosError } from 'axios';
import axiosInstance from '@/helpers/axios-instance';
import userState from '@/utils/user-state';

import ThemeToggle from '@/components/theme-toggle-button';
function signin() {
const navigate = useNavigate();
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
reset,
setError
setError,
} = useForm<TSignInSchema>({ resolver: zodResolver(signInSchema) });

const onSubmit = async (data: FieldValues) => {
try {
const response = axiosInstance.post('/api/auth/email-password/signin',
data
);
const response = axiosInstance.post('/api/auth/email-password/signin', data);

toast.promise(response, {
pending: 'Checking credentials ...',
success: {
render({ data }) {
const userId = data?.data?.data?.user?._id;
const userRole = data?.data?.data?.user?.role;
userState.setUser({ _id: userId, role: userRole })
reset()
navigate('/')
return data?.data?.message
userState.setUser({ _id: userId, role: userRole });
reset();
navigate('/');
return data?.data?.message;
},
},
error: {
render({ data }) {
if (data instanceof AxiosError) {
if (data?.response?.data?.message.includes('User')) {
setError('userNameOrEmail',{ type: 'manual', message: data?.response?.data?.message});
setError('userNameOrEmail', {
type: 'manual',
message: data?.response?.data?.message,
});
} else {
setError("password",{ type: 'manual', message: data?.response?.data?.message});
setError('password', { type: 'manual', message: data?.response?.data?.message });
}
}
return "Signin failed"
return 'Signin failed';
},
},
}
)
});

return (await response).data
return (await response).data;
} catch (error) {
if (isAxiosError(error)) {
console.error(error.response?.data?.message);
Expand All @@ -65,12 +65,15 @@ function signin() {
};

return (
<div className="m-4 flex-grow cursor-default bg-white py-4">
<div className="mb-4 flex justify-center">
<div className="flex-grow cursor-default bg-white py-4 dark:bg-dark-card">
<div className="m-4 mb-4 flex justify-center">
<div className="flex w-full items-center justify-center">
<h2 className="w-3/4 text-center text-lg font-bold text-black sm:text-xl">
<h2 className="w-3/4 pl-48 text-center text-lg font-bold text-black dark:text-dark-primary sm:text-xl">
Sign in to WanderLust
</h2>
<div className="flex items-center justify-end px-4 sm:px-20">
<ThemeToggle />
</div>
</div>
</div>
<div className="m-2 mt-8 flex flex-col items-center justify-center gap-2">
Expand All @@ -80,7 +83,7 @@ function signin() {
{...register('userNameOrEmail')}
type="text"
placeholder="Username or Email"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm dark:bg-dark-field dark:text-dark-textInField"
/>
{errors.userNameOrEmail && (
<p className="p-3 text-xs text-red-500">{`${errors.userNameOrEmail.message}`}</p>
Expand All @@ -92,7 +95,7 @@ function signin() {
{...register('password')}
type="password"
placeholder="Password"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm dark:bg-dark-field dark:text-dark-textInField"
/>
{errors.password && (
<p className="p-3 text-xs text-red-500">{`${errors.password.message}`}</p>
Expand All @@ -102,12 +105,12 @@ function signin() {
<button
disabled={isSubmitting}
type="submit"
className="flex w-full items-center justify-center rounded-lg bg-neutral-800 p-3 text-base font-medium text-light disabled:bg-neutral-600 sm:text-lg sm:font-semibold"
className="flex w-full items-center justify-center rounded-lg bg-neutral-800 p-3 text-base font-medium text-light disabled:bg-neutral-600 dark:bg-dark-button sm:text-lg sm:font-semibold"
>
Log In
</button>
</form>
<div className="mt-2 flex w-5/6 flex-col items-center justify-center gap-4 text-center text-sm font-normal sm:text-base">
<div className="mt-2 flex w-5/6 flex-col items-center justify-center gap-4 text-center text-sm font-normal dark:text-dark-primary sm:text-base">
<p>
Don't have an account?
<Link to={'/signup'} className="text-blue-600 hover:text-blue-500">
Expand All @@ -121,18 +124,18 @@ function signin() {

<Link
to={'/google-auth'}
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 md:w-3/4 lg:w-2/5"
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 dark:border-gray-700 dark:hover:bg-gray-700 md:w-3/4 lg:w-2/5"
>
<img className="h-4 w-6 pl-1 sm:h-5 sm:w-10" src={AddGoogleIcon} />
<span className="text-sm sm:text-base">Continue with Google</span>
<span className="text-sm dark:text-dark-primary sm:text-base">Continue with Google</span>
</Link>

<Link
to={'/github-auth'}
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 md:w-3/4 lg:w-2/5"
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 dark:border-gray-700 dark:hover:bg-gray-700 md:w-3/4 lg:w-2/5"
>
<img className="h-4 w-6 sm:h-5 sm:w-10" src={AddGithubIcon} />
<span className="text-sm sm:text-base">Continue with Github</span>
<span className="text-sm dark:text-dark-primary sm:text-base">Continue with Github</span>
</Link>
</div>
</div>
Expand Down
54 changes: 27 additions & 27 deletions frontend/src/pages/signup-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,46 @@ import { toast } from 'react-toastify';
import { AxiosError, isAxiosError } from 'axios';
import axiosInstance from '@/helpers/axios-instance';
import userState from '@/utils/user-state';

import ThemeToggle from '@/components/theme-toggle-button';
function signup() {
const navigate = useNavigate();
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
reset,
setError
setError,
} = useForm<TSignUpSchema>({ resolver: zodResolver(signUpSchema) });

const onSubmit = async (data: FieldValues) => {
try {
const res = axiosInstance.post('/api/auth/email-password/signup', data)
const res = axiosInstance.post('/api/auth/email-password/signup', data);
toast.promise(res, {
pending: 'Creating account ...',
success: {
render({ data }) {
const userId = data?.data?.data?.user?._id;
const userRole = data?.data?.data?.user?.role;
userState.setUser({ _id: userId, role: userRole })
reset()
navigate('/')
return data?.data?.message
userState.setUser({ _id: userId, role: userRole });
reset();
navigate('/');
return data?.data?.message;
},
},
error: {
render({ data }) {
if (data instanceof AxiosError) {
if (data?.response?.data?.message.includes('Username')) {
setError('userName',{ type: 'manual', message: data?.response?.data?.message });
setError('userName', { type: 'manual', message: data?.response?.data?.message });
} else {
setError('email',{ type: 'manual', message: data?.response?.data?.message });
setError('email', { type: 'manual', message: data?.response?.data?.message });
}
}
return "Signup failed"
return 'Signup failed';
},
},
}
)
return (await res).data

});
return (await res).data;
} catch (error) {
if (isAxiosError(error)) {
console.error(error.response?.data?.message);
Expand All @@ -61,14 +59,16 @@ function signup() {
}
};


return (
<div className="m-4 flex-grow cursor-default bg-white py-4">
<div className="mb-4 flex justify-center">
<div className="flex-grow cursor-default bg-white py-4 dark:bg-dark-card">
<div className="m-4 mb-4 flex justify-center">
<div className="flex w-full items-center justify-center">
<h2 className="w-3/4 text-center text-lg font-bold text-black sm:text-xl">
<h2 className="w-3/4 pl-48 text-center text-lg font-bold text-black dark:text-dark-primary sm:text-xl">
Sign up to WanderLust
</h2>
<div className="flex items-center justify-end px-4 sm:px-20">
<ThemeToggle />
</div>
</div>
</div>
<div className="m-2 mt-8 flex flex-col items-center justify-center gap-2">
Expand All @@ -78,7 +78,7 @@ function signup() {
{...register('userName')}
type="text"
placeholder="Username"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500"
className="dark:placholder w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm dark:bg-dark-field dark:text-dark-textInField"
/>
{errors.userName && (
<p className="p-3 text-xs text-red-500">{`${errors.userName.message}`}</p>
Expand All @@ -89,7 +89,7 @@ function signup() {
{...register('fullName')}
type="text"
placeholder="Name"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm dark:bg-dark-field dark:text-dark-textInField"
/>
{errors.fullName && (
<p className="p-3 text-xs text-red-500">{`${errors.fullName.message}`}</p>
Expand All @@ -100,7 +100,7 @@ function signup() {
{...register('email')}
type="email"
placeholder="Email"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm dark:bg-dark-field dark:text-dark-textInField"
/>
{errors.email && (
<p className="p-3 text-xs text-red-500">{`${errors.email.message}`}</p>
Expand All @@ -111,7 +111,7 @@ function signup() {
{...register('password')}
type="password"
placeholder="Password"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm dark:bg-dark-field dark:text-dark-textInField"
/>
{errors.password && (
<p className="p-3 text-xs text-red-500">{`${errors.password.message}`}</p>
Expand All @@ -122,7 +122,7 @@ function signup() {
{...register('confirmPassword')}
type="password"
placeholder="Confirm Password"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500"
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm dark:bg-dark-field dark:text-dark-textInField"
/>
{errors.confirmPassword && (
<p className="p-3 text-xs text-red-500">{`${errors.confirmPassword.message}`}</p>
Expand All @@ -131,12 +131,12 @@ function signup() {
<button
disabled={isSubmitting}
type="submit"
className="flex w-full items-center justify-center rounded-lg bg-neutral-800 p-3 text-base font-medium text-light disabled:bg-neutral-600 sm:text-lg sm:font-semibold"
className="flex w-full items-center justify-center rounded-lg bg-neutral-800 p-3 text-base font-medium text-light disabled:bg-neutral-600 dark:bg-dark-button sm:text-lg sm:font-semibold"
>
Sign Up
</button>
</form>
<div className="mt-2 flex w-5/6 flex-col items-center justify-center gap-4 text-center text-sm font-normal sm:text-base">
<div className="mt-2 flex w-5/6 flex-col items-center justify-center gap-4 text-center text-sm font-normal dark:text-dark-primary sm:text-base">
<p>
Already have an account?
<Link to={'/signin'} className="text-blue-600 hover:text-blue-500">
Expand All @@ -150,15 +150,15 @@ function signup() {

<Link
to={'/google-auth'}
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 md:w-3/4 lg:w-2/5"
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 dark:border-gray-700 dark:text-dark-primary dark:hover:bg-gray-700 md:w-3/4 lg:w-2/5"
>
<img className="h-4 w-6 pl-1 sm:h-5 sm:w-10" src={AddGoogleIcon} />
<span className="text-sm sm:text-base">Continue with Google</span>
</Link>

<Link
to={'/github-auth'}
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 md:w-3/4 lg:w-2/5"
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 dark:border-gray-700 dark:text-dark-primary dark:hover:bg-gray-700 md:w-3/4 lg:w-2/5"
>
<img className="h-4 w-6 sm:h-5 sm:w-10" src={AddGithubIcon} />
<span className="text-sm sm:text-base">Continue with Github</span>
Expand Down
3 changes: 3 additions & 0 deletions frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default {
title: colors.slate[50],
description: colors.slate[400],
info: colors.slate[500],
field: colors.slate[900],
button: colors.slate[700],
textInField: colors.slate[50]
},
light: {
DEFAULT: colors.slate[50],
Expand Down

0 comments on commit 19138dc

Please sign in to comment.