Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT/Added Job Management Page #300

Merged
merged 23 commits into from
Oct 21, 2024

Conversation

dev13-suthar
Copy link
Contributor

->Admin can visit the /manage page and see all list of active jobs, and Delete them As Well.
->From the Action button admin can edit and delete JOBS.
->Admin can Create Post. (redirects to /create Page).
->Fixed Typo in Footer
-> In this PR i have only done Delete Job Functionality which is deactivated because there is no session Management as Now.
Fixes:[#284]
Screenshot 2024-09-05 183753

@dev13-suthar
Copy link
Contributor Author

@VineeTagarwaL-code

@VineeTagarwaL-code
Copy link
Collaborator

Nice pr, can you fix the conflicts and give a video of your functioning

@dev13-suthar
Copy link
Contributor Author

ok

@dev13-suthar
Copy link
Contributor Author

100xJobs.-.Google.Chrome.2024-09-17.13-40-44.mp4

@dev13-suthar
Copy link
Contributor Author

@VineeTagarwaL-code solved conflicts, Fixed UI bug( JOB was being displayed even after deleting until we perform hard reload). tag me once you review this.

@VineeTagarwaL-code
Copy link
Collaborator

this looks great now, a good starting point can you one more feature where the admin can approve jobs will be really usefull

@dev13-suthar
Copy link
Contributor Author

Yes i can do that, but since there is no session logic, Signup,Register how can i determine logged in User is Admin or Not,? Why there is no signin/signup options?

@VineeTagarwaL-code
Copy link
Collaborator

can you add that feature here in this PR itself, was gonna open a new one but if you can do it it will be great !

@dev13-suthar
Copy link
Contributor Author

sure i'll take this.
so i have to done signin,signup logic with nextAuth and then add job approval functionality. right?

@VineeTagarwaL-code
Copy link
Collaborator

yeah it already there the code is not purged

@dev13-suthar
Copy link
Contributor Author

dev13-suthar commented Sep 19, 2024

summary:
Added /api/auth/...nextAuth,
cleaned authOptions code so we can use session,
/manage admin only page,
admin can approve Jobs.
video:

Demo.mp4

commit these?

@VineeTagarwaL-code
Copy link
Collaborator

show auth flow with logout

@dev13-suthar
Copy link
Contributor Author

sorry for keep this hanging , i will get it done by today or tomorrow

@dev13-suthar
Copy link
Contributor Author

100xJobs.-.Google.Chrome.2024-09-22.10-56-59.mp4

@dev13-suthar
Copy link
Contributor Author

We can raise issue for better login and logout button and signin/signup form

@VineeTagarwaL-code
Copy link
Collaborator

comment out the login flow, only ahve for admin a lot of pr has this and they are more better on this tbh

@dev13-suthar
Copy link
Contributor Author

100xJobs.-.Google.Chrome.2024-09-22.16-53-40.mp4

ready to merge i think

@dev13-suthar
Copy link
Contributor Author

@VineeTagarwaL-code

@VineeTagarwaL-code
Copy link
Collaborator

fix conflicts, need to merge

@dev13-suthar
Copy link
Contributor Author

fixing

@VineeTagarwaL-code
Copy link
Collaborator

build fails, fix please

@dev13-suthar
Copy link
Contributor Author

fixed

@dev13-suthar
Copy link
Contributor Author

it should work now

>(async (data) => {
const result = deleteJobByIdSchema.parse(data);
const { id } = result;
const deletedJob = await prisma.job.delete({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets create a new field in job (deleted) which will flag it true or false instead of removing it from db

ApproveJobSchemaType,
ServerActionReturnType<ApprovedJobID>
>(async (session, data) => {
if (session.user.role === 'USER') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be an admin check here in case we add users with other roles

if (session.user.role === 'USER') {
throw new Error('Unauth Access');
}
const result = ApproveJobSchema.parse(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use safeParse instead of parse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but other actions are using parse only, if i use safeparse there will be an other check for if(data.success)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes , it's better to safe parse

JobQuerySchemaType,
ServerActionReturnType<getAllJobsAdditonalType>
>(async (session, data) => {
if (session.user.role === 'USER') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refer the comment above , try makin a wrapper on top of the with session function e.g. withAdminServerAction , something like that so you wont have to repeat this step

});

export const getAllJobsForAdmin = withSession<
//not the ideal action we should make getAllJobs() better so we can have option to display verified and unverified jobs by Inputs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do , add that in the getAll routes itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what im thinking is, if user role is admin return all job whether they are verified or unverified and if role is user return only verified job/ should i go with this?

<div>
<Button
onClick={() => {
router.push('/create');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use link tag instead


const JobManagementTable = ({ jobs, searchParams, initialJobs }: props) => {
const { toast } = useToast();
const [DispJobs, setDispJobs] = useState<JobType[]>(initialJobs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of just the initial jobs , can you make all of them server rendered ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was server rendered before, but because of server renders when something gets change like if job approves then the datatable was not syncing with the DB unless u hard refresh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll have to revalidate the route , and then it'll work

}
};

const refreshJobs = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this function ? is it just to fetch the latest changes ?.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it calls everytime searchparams changes to fetch and put latest job with local state variable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this if youre rendering table on server side

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let this merge, i will update it later

const totalPages =
Math.ceil((jobs.additional?.totalJobs || 0) / JOBS_PER_PAGE) ||
DEFAULT_PAGE;
const currentPage = parseInt(searchParams.page?.toString()) || DEFAULT_PAGE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need the toString() here , if you parse the search params correctly before passing it to this table component , we wont need it

<PaginationPreviousButton
searchParams={searchParams}
currentPage={currentPage}
baseUrl={APP_PATHS.JOBS}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also remove the need for this to be passed , its not required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pagination not required?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no , we don't need the baseUrl to be paaed

@dev13-suthar
Copy link
Contributor Author

@VineeTagarwaL-code done ready to merge new feat

@dev13-suthar
Copy link
Contributor Author

merge these before major updates that will be coming like user onboarding. @VineeTagarwaL-code

@dev13-suthar
Copy link
Contributor Author

@VineeTagarwaL-code solved all reviews bugs and now Table is also Server rendered.

@VineeTagarwaL-code
Copy link
Collaborator

fix conflicts need to merge

@dev13-suthar
Copy link
Contributor Author

@VineeTagarwaL-code done

@VineeTagarwaL-code
Copy link
Collaborator

give vid ref of current status of the pr

@dev13-suthar
Copy link
Contributor Author

finalPreview.mp4

@VineeTagarwaL-code VineeTagarwaL-code merged commit b195ae9 into code100x:main Oct 21, 2024
1 check passed
@VineeTagarwaL-code
Copy link
Collaborator

A new issue will open to improve the ui of this page and possible add more functionality but great work

Make sure you post your pr getting merged on x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants