generated from sripwoud/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set question to (in)active (#86)
* feat: add `author` column to `questions` * feat: define question page * feat(client): set question to inactive
- Loading branch information
Showing
12 changed files
with
117 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use client' | ||
import { useUser } from '@account-kit/react' | ||
import { Loader } from 'client/c/Loader' | ||
import { withAuth } from 'client/components/withAuth' | ||
import { trpc } from 'client/l/trpc' | ||
import { useEffect } from 'react' | ||
|
||
const QuestionDetails = ({ params: { questionId: questionIdStr } }: { params: { questionId: string } }) => { | ||
const questionId = Number.parseInt(questionIdStr) | ||
const user = useUser() | ||
const { mutate: toggle, isPending } = trpc.questions.toggle.useMutation() | ||
const { data: question, isLoading, refetch } = trpc.questions.find.useQuery({ questionId }, { | ||
select: ({ data }) => data, | ||
}) | ||
|
||
useEffect(() => { | ||
refetch() | ||
}, [isPending]) | ||
|
||
if (isLoading || question === undefined || question === null) return <Loader /> | ||
return ( | ||
<div> | ||
<h1 className='text-2xl'>{question.title}</h1> | ||
<p>yes: {question.yes}</p> | ||
<p>no: {question.no}</p> | ||
{user?.email === question.author && ( | ||
<button | ||
type='button' | ||
onClick={() => { | ||
toggle({ active: !question.active, questionId }) | ||
}} | ||
> | ||
Set {question.active ? 'Ina' : 'A'}ctive | ||
</button> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default withAuth(QuestionDetails) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
apps/client/src/components/QuestionCard/YN/YNQuestionStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './create-question.dto' | ||
export * from './find-all-questions.dto' | ||
export * from './find-question.dto' | ||
export * from './toggle-question.dto' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from 'zod' | ||
|
||
export const ToggleQuestionDto = z.object({ | ||
active: z.boolean(), | ||
questionId: z.number().positive(), | ||
}) | ||
|
||
export type ToggleQuestionDto = z.infer<typeof ToggleQuestionDto> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
supabase/migrations/20241023064101_create_questions_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters