Skip to content

Commit

Permalink
updated/profile-section
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutoshpadhi629 committed Oct 11, 2024
1 parent 34ee6a7 commit c420902
Show file tree
Hide file tree
Showing 19 changed files with 421 additions and 16 deletions.
66 changes: 66 additions & 0 deletions src/actions/user.profile.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,69 @@ export const addUserResume = async (resume: string) => {
return new ErrorHandler('Internal server error', 'DATABASE_ERROR');
}
};

export const getUserExperience = async () => {
const auth = await getServerSession(authOptions);

if (!auth || !auth?.user?.id)
throw new ErrorHandler('Not Authorized', 'UNAUTHORIZED');
try {
const res = await prisma.experience.findMany({
where: {
userId: auth.user.id,
},
});
return new SuccessResponse(
'Experience SuccessFully Fetched',
200,
res
).serialize();
} catch (_error) {
return new ErrorHandler('Internal server error', 'DATABASE_ERROR');
}
};
export const getUserProjects = async () => {
const auth = await getServerSession(authOptions);

if (!auth || !auth?.user?.id)
throw new ErrorHandler('Not Authorized', 'UNAUTHORIZED');
try {
const res = await prisma.project.findMany({
where: {
userId: auth.user.id,
},
});
return new SuccessResponse(
'Project SuccessFully Fetched',
200,
res
).serialize();
} catch (_error) {
return new ErrorHandler('Internal server error', 'DATABASE_ERROR');
}
};

export const getUserDetails = async () => {
const auth = await getServerSession(authOptions);

if (!auth || !auth?.user?.id)
throw new ErrorHandler('Not Authorized', 'UNAUTHORIZED');
try {
const res = await prisma.user.findFirst({
where: {
id: auth.user.id,
},
select: {
skills: true,
resume: true,
},
});
return new SuccessResponse(
'Project SuccessFully Fetched',
200,
res
).serialize();
} catch (_error) {
return new ErrorHandler('Internal server error', 'DATABASE_ERROR');
}
};
2 changes: 1 addition & 1 deletion src/app/create-profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { redirect } from 'next/navigation';
export default async function Home() {
const session = await getServerSession(authOptions);
if (!session || session.user.role !== 'USER') redirect('/');
if (session.user.onBoard === true) redirect('/profile');
if (session.user.onBoard === true) redirect('/jobs');
return (
<div className="flex flex-col justify-center place-items-center">
<h1 className="text-xl font-bold md:text-3xl md:font-extrabold m-auto">
Expand Down
10 changes: 0 additions & 10 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@ import Faqs from '@/components/Faqs';
import HeroSection from '@/components/hero-section';
import { JobLanding } from '@/components/job-landing';
import Testimonials from '@/components/Testimonials';
import { authOptions } from '@/lib/authOptions';
import { getServerSession } from 'next-auth';
import { redirect } from 'next/navigation';

const HomePage = async () => {
const session = await getServerSession(authOptions);
{
session &&
session.user.role === 'USER' &&
!session.user.onBoard &&
redirect('/create-profile');
}
return (
<div>
<HeroSection />
Expand Down
20 changes: 20 additions & 0 deletions src/app/profile/experience/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client';
import { UserExperience } from '@/components/profile/UserExperience';
import APP_PATHS from '@/config/path.config';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import React, { useEffect } from 'react';

export default function AccountExperiencePage() {
const router = useRouter();
const session = useSession();
useEffect(() => {
if (session.status !== 'loading' && session.status === 'unauthenticated')
router.push(`${APP_PATHS.SIGNIN}?redirectTo=/profile`);
}, [session.status, router]);
return (
<div>
<UserExperience />
</div>
);
}
21 changes: 20 additions & 1 deletion src/app/profile/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use client';
import { getUserDetails } from '@/actions/user.profile.actions';
import Sidebar from '@/components/profile/sidebar';
import APP_PATHS from '@/config/path.config';
import { useSession } from 'next-auth/react';
Expand All @@ -11,7 +12,25 @@ const ProfileLayout = ({ children }: { children: React.ReactNode }) => {
useEffect(() => {
if (session.status !== 'loading' && session.status === 'unauthenticated')
router.push(`${APP_PATHS.SIGNIN}?redirectTo=/profile`);
}, [session.status]);
}, [session.status, router]);
useEffect(() => {
async function fetchUserDetails() {
try {
const res = await getUserDetails();
if (res.status) {
localStorage.setItem(
'skills',
JSON.stringify(res.additional?.skills)
);
localStorage.setItem(
'resume',
JSON.stringify(res.additional?.resume)
);
}
} catch (_error) {}
}
fetchUserDetails();
}, []);
return (
<div className="container flex max-md:flex-col md:gap-5 w-full relative">
<Sidebar />
Expand Down
3 changes: 2 additions & 1 deletion src/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const ProfilePage = () => {
useEffect(() => {
if (session.status !== 'loading' && session.status === 'unauthenticated')
router.push(`${APP_PATHS.SIGNIN}?redirectTo=/create`);
}, [session.status]);
}, [session.status, router]);

return (
<div className="md:container flex flex-col w-full">
<div className="flex justify-between items-start mb-4 w-full">
Expand Down
20 changes: 20 additions & 0 deletions src/app/profile/projects/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client';
import { UserProjects } from '@/components/profile/UserProject';
import APP_PATHS from '@/config/path.config';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import React, { useEffect } from 'react';

export default function AccountProjectPage() {
const router = useRouter();
const session = useSession();
useEffect(() => {
if (session.status !== 'loading' && session.status === 'unauthenticated')
router.push(`${APP_PATHS.SIGNIN}?redirectTo=/profile`);
}, [session.status, router]);
return (
<div className="overflow-x-hidden">
<UserProjects />
</div>
);
}
20 changes: 20 additions & 0 deletions src/app/profile/resume/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client';
import { UserResume } from '@/components/profile/UserResume';
import APP_PATHS from '@/config/path.config';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import React, { useEffect } from 'react';

export default function AccountResumePage() {
const router = useRouter();
const session = useSession();
useEffect(() => {
if (session.status !== 'loading' && session.status === 'unauthenticated')
router.push(`${APP_PATHS.SIGNIN}?redirectTo=/profile`);
}, [session.status, router]);
return (
<div className="m-auto">
<UserResume />
</div>
);
}
2 changes: 1 addition & 1 deletion src/app/profile/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const AccountSettingsPage = () => {
useEffect(() => {
if (session.status !== 'loading' && session.status === 'unauthenticated')
router.push(`${APP_PATHS.SIGNIN}?redirectTo=/profile`);
}, [session.status]);
}, [session.status, router]);
return (
<div className="md:container flex flex-col w-full">
<div className="flex justify-between items-center mb-4">
Expand Down
20 changes: 20 additions & 0 deletions src/app/profile/skills/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client';
import { UserSkills } from '@/components/profile/UserSkills';
import APP_PATHS from '@/config/path.config';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import React, { useEffect } from 'react';

export default function AccountResumePage() {
const router = useRouter();
const session = useSession();
useEffect(() => {
if (session.status !== 'loading' && session.status === 'unauthenticated')
router.push(`${APP_PATHS.SIGNIN}?redirectTo=/profile`);
}, [session.status, router]);
return (
<div>
<UserSkills />
</div>
);
}
86 changes: 86 additions & 0 deletions src/components/profile/UserExperience.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { getUserExperience } from '@/actions/user.profile.actions';
import { useEffect, useState } from 'react';
import { useToast } from '../ui/use-toast';
import { Experience } from '@prisma/client';
import { Card, CardContent, CardHeader, CardTitle } from '../ui/card';
import _ from 'lodash';

export function UserExperience() {
const { toast } = useToast();
const [experiences, setExperiences] = useState<Experience[] | undefined>();

useEffect(() => {
async function fetchExperience() {
try {
const res = await getUserExperience();
if (!res.status) {
toast({
title: 'Cannot Fetch Experiences! Please Try Again Later',
variant: 'destructive',
});
}
if (res.status) {
setExperiences(res.additional);
}
} catch (_error) {
toast({
title: 'Cannot Fetch Experiences! Please Try Again Later',
variant: 'destructive',
});
}
}

fetchExperience();
}, []);

if (!experiences) {
return null;
}

return (
<div className="space-y-2 mb-2">
{experiences.map((item: Experience) => (
<Card
key={item.id}
className="border-2 hover:bg-slate-100 dark:hover:bg-slate-900 text-black dark:text-white transition-shadow duration-300"
>
<CardHeader>
<CardTitle className="text-lg font-semibold">
<strong>Company Name: </strong>
{item.companyName}
</CardTitle>
</CardHeader>
<CardContent>
<p className="mb-2">
<strong>Designation:</strong> {item.designation}
</p>
<p className="mb-2">
<strong>Employment Type:</strong>{' '}
{_.startCase(item.EmploymentType)}
</p>
<p className="mb-2">
<strong>Work Mode:</strong> {item.workMode}
</p>
<p className="mb-2">
<strong>Current Status:</strong>{' '}
{item.currentWorkStatus
? 'Currently Employed here'
: 'Not Currently Employed here'}
</p>
<p className="mb-2">
<strong>Duration:</strong>{' '}
{new Date(item.startDate).toLocaleDateString()}{' '}
{item.endDate
? ` - ${new Date(item.endDate).toLocaleDateString()}`
: ' - Present'}
</p>
<p className="mb-4">
<strong>Description: </strong>
{item.description}
</p>
</CardContent>
</Card>
))}
</div>
);
}
Loading

0 comments on commit c420902

Please sign in to comment.