Skip to content

Commit

Permalink
feat(client): implement forum answer posting
Browse files Browse the repository at this point in the history
  • Loading branch information
umitcan07 committed Nov 20, 2024
1 parent a261471 commit 51695d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions client/src/routes/Forum/Forum.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionFunction, LoaderFunction } from "react-router";
import { ActionFunction, LoaderFunction, redirect } from "react-router";
import { safeParse } from "valibot";
import apiClient from "../../api";
import { USER } from "../../constants";
Expand Down Expand Up @@ -190,8 +190,9 @@ export const bookmarkForumAction = (async ({
}) satisfies ActionFunction;

export const answerForumAction = (async ({ request, params }) => {
// if not logged in, redirect to login page and add a toast
// If not logged in, render a warning message and return redirect login.

const postId = params.postId;
const user = sessionStorage.getObject(USER) || localStorage.getObject(USER);
if (!user) {
useToastStore.getState().add({
Expand All @@ -202,6 +203,7 @@ export const answerForumAction = (async ({ request, params }) => {
description: "You need to log in to answer forum questions.",
},
});
return redirect("/login");
}

const formData = await request.formData();
Expand Down
6 changes: 3 additions & 3 deletions client/src/routes/Forum/Question.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Form, useFetcher, useSearchParams } from "react-router-dom";
import { useFetcher, useSearchParams } from "react-router-dom";
import { useLoaderData, useRouteLoaderData } from "react-router-typesafe";
import { buttonClass } from "../../components/button";
import { ForumAnswerCard } from "../../components/forum-answer-card";
Expand Down Expand Up @@ -29,7 +29,7 @@ export const ForumQuestion = () => {
);
})}
</div>
<Form
<answerFetcher.Form
action="answer"
method="POST"
className="flex w-full max-w-xl flex-col items-center justify-center gap-4"
Expand All @@ -51,7 +51,7 @@ export const ForumQuestion = () => {
>
Post Comment
</button>
</Form>
</answerFetcher.Form>
</main>
</div>
);
Expand Down

0 comments on commit 51695d1

Please sign in to comment.