mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
feat: history view in feedback popover
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { ClockIcon } from "lucide-react";
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
@@ -106,8 +107,11 @@ export function FeedbackPopover() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type View = "compose" | "history";
|
||||||
|
|
||||||
function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
|
function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
|
||||||
const { entries, isSubmitting, submit } = useFeedback();
|
const { entries, isSubmitting, submit } = useFeedback();
|
||||||
|
const [view, setView] = useState<View>("compose");
|
||||||
|
|
||||||
const form = useForm<FeedbackFormValues>({
|
const form = useForm<FeedbackFormValues>({
|
||||||
defaultValues: { message: "" },
|
defaultValues: { message: "" },
|
||||||
@@ -124,6 +128,33 @@ function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (view === "history") {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<div
|
||||||
|
className="max-h-72 overflow-y-auto divide-y"
|
||||||
|
style={{
|
||||||
|
maskImage:
|
||||||
|
"linear-gradient(to bottom, black 80%, transparent 100%)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{entries.map((entry) => (
|
||||||
|
<FeedbackEntryItem key={entry.id} entry={entry} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="border-t px-3 py-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setView("compose")}
|
||||||
|
className="text-xs text-muted-foreground/60 hover:text-muted-foreground transition-colors"
|
||||||
|
>
|
||||||
|
← Back
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<Form persistKey={PERSIST_KEY} {...form}>
|
<Form persistKey={PERSIST_KEY} {...form}>
|
||||||
@@ -143,43 +174,41 @@ function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<div className="flex justify-end border-t px-3 py-2 gap-2">
|
<div className="flex items-center justify-between border-t px-3 py-2">
|
||||||
{!form.watch("message").trim() && (
|
{entries.length > 0 ? (
|
||||||
<Button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
onClick={() => setView("history")}
|
||||||
size="sm"
|
className="flex items-center gap-1.5 text-xs text-muted-foreground/60 hover:text-muted-foreground transition-colors"
|
||||||
onClick={onClose}
|
|
||||||
>
|
>
|
||||||
Cancel
|
<ClockIcon className="size-3" />
|
||||||
</Button>
|
{entries.length}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<span />
|
||||||
)}
|
)}
|
||||||
<Button
|
<div className="flex gap-2">
|
||||||
type="submit"
|
{!form.watch("message").trim() && (
|
||||||
size="sm"
|
<Button
|
||||||
disabled={isSubmitting || !form.watch("message").trim()}
|
type="button"
|
||||||
>
|
variant="outline"
|
||||||
{isSubmitting ? <Spinner /> : "Send"}
|
size="sm"
|
||||||
</Button>
|
onClick={onClose}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
size="sm"
|
||||||
|
disabled={isSubmitting || !form.watch("message").trim()}
|
||||||
|
>
|
||||||
|
{isSubmitting ? <Spinner /> : "Send"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
{entries.length > 0 && (
|
|
||||||
<div className="border-t overflow-hidden">
|
|
||||||
<div
|
|
||||||
className="max-h-52 overflow-y-auto divide-y"
|
|
||||||
style={{
|
|
||||||
maskImage:
|
|
||||||
"linear-gradient(to bottom, black 70%, transparent 100%)",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{entries.map((entry) => (
|
|
||||||
<FeedbackEntryItem key={entry.id} entry={entry} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user