style: clean up code with prettier and eslint
This commit is contained in:
1 parent
60278b9e71
commit
fb8e77bb68
378 files changed
+22407
-20689
No files matched your search
@@ -1,71 +1,65 @@
|
||||
'use client'
|
||||
"use client";
|
||||
|
||||
import { GripVertical, Pencil, Plus, Trash2 } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { addPollQuestion, deletePollQuestion, updatePollQuestion } from '@/actions/polls'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { useServerAction } from '@/hooks/use-server-action'
|
||||
import { GripVertical, Pencil, Plus, Trash2 } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { addPollQuestion, deletePollQuestion, updatePollQuestion } from "@/actions/polls";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
|
||||
interface Question {
|
||||
id: number
|
||||
question: string
|
||||
type: string
|
||||
sortOrder: number
|
||||
options: string
|
||||
id: number;
|
||||
question: string;
|
||||
type: string;
|
||||
sortOrder: number;
|
||||
options: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
pollId: number
|
||||
questions: Question[]
|
||||
pollId: number;
|
||||
questions: Question[];
|
||||
}
|
||||
|
||||
export function PollQuestionsManager({ pollId, questions }: Props) {
|
||||
const { run, isPending } = useServerAction()
|
||||
const [showForm, setShowForm] = useState(false)
|
||||
const [editingId, setEditingId] = useState<number | null>(null)
|
||||
const { run, isPending } = useServerAction();
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [form, setForm] = useState({
|
||||
question: '',
|
||||
type: 'single',
|
||||
question: "",
|
||||
type: "single",
|
||||
sortOrder: questions.length,
|
||||
options: '',
|
||||
})
|
||||
options: "",
|
||||
});
|
||||
|
||||
function resetForm() {
|
||||
setForm({ question: '', type: 'single', sortOrder: questions.length, options: '' })
|
||||
setEditingId(null)
|
||||
setShowForm(false)
|
||||
setForm({ question: "", type: "single", sortOrder: questions.length, options: "" });
|
||||
setEditingId(null);
|
||||
setShowForm(false);
|
||||
}
|
||||
|
||||
function handleEdit(q: Question) {
|
||||
setForm({ question: q.question, type: q.type, sortOrder: q.sortOrder, options: q.options })
|
||||
setEditingId(q.id)
|
||||
setShowForm(true)
|
||||
setForm({ question: q.question, type: q.type, sortOrder: q.sortOrder, options: q.options });
|
||||
setEditingId(q.id);
|
||||
setShowForm(true);
|
||||
}
|
||||
|
||||
function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
e.preventDefault();
|
||||
if (editingId) {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: explicitly chosen here, see surrounding code
|
||||
run(() => updatePollQuestion({ id: editingId, ...form } as any), {
|
||||
successMessage: 'Question updated!',
|
||||
})
|
||||
successMessage: "Question updated!",
|
||||
});
|
||||
} else {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: explicitly chosen here, see surrounding code
|
||||
run(() => addPollQuestion({ pollId, ...form } as any), {
|
||||
successMessage: 'Question added!',
|
||||
})
|
||||
successMessage: "Question added!",
|
||||
});
|
||||
}
|
||||
resetForm()
|
||||
resetForm();
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -75,8 +69,8 @@ export function PollQuestionsManager({ pollId, questions }: Props) {
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
resetForm()
|
||||
setShowForm(!showForm)
|
||||
resetForm();
|
||||
setShowForm(!showForm);
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1" /> Add Question
|
||||
@@ -122,7 +116,7 @@ export function PollQuestionsManager({ pollId, questions }: Props) {
|
||||
className="w-full rounded-md border bg-transparent px-3 py-2 text-sm min-h-[80px]"
|
||||
value={form.options}
|
||||
onChange={(e) => setForm({ ...form, options: e.target.value })}
|
||||
placeholder={'Option A\nOption B\nOption C'}
|
||||
placeholder={"Option A\nOption B\nOption C"}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2 justify-end">
|
||||
@@ -130,7 +124,7 @@ export function PollQuestionsManager({ pollId, questions }: Props) {
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" size="sm" disabled={isPending}>
|
||||
{editingId ? 'Update' : 'Add'}
|
||||
{editingId ? "Update" : "Add"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -155,13 +149,10 @@ export function PollQuestionsManager({ pollId, questions }: Props) {
|
||||
{q.options && (
|
||||
<div className="mt-1 text-xs text-muted-foreground">
|
||||
{q.options
|
||||
.split('\n')
|
||||
.split("\n")
|
||||
.filter(Boolean)
|
||||
.map((opt) => (
|
||||
<span
|
||||
key={opt}
|
||||
className="inline-block mr-2 bg-muted px-1.5 py-0.5 rounded mb-1"
|
||||
>
|
||||
<span key={opt} className="inline-block mr-2 bg-muted px-1.5 py-0.5 rounded mb-1">
|
||||
{opt}
|
||||
</span>
|
||||
))}
|
||||
@@ -169,12 +160,7 @@ export function PollQuestionsManager({ pollId, questions }: Props) {
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-1 shrink-0">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => handleEdit(q)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => handleEdit(q)}>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -183,7 +169,7 @@ export function PollQuestionsManager({ pollId, questions }: Props) {
|
||||
className="h-7 w-7"
|
||||
onClick={() =>
|
||||
run(() => deletePollQuestion({ id: q.id }), {
|
||||
successMessage: 'Question deleted',
|
||||
successMessage: "Question deleted",
|
||||
})
|
||||
}
|
||||
>
|
||||
@@ -195,5 +181,5 @@ export function PollQuestionsManager({ pollId, questions }: Props) {
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user