Skip to content

Commit 66e4367

Browse files
committed
feat: history view in feedback popover
1 parent 8161de0 commit 66e4367

File tree

1 file changed

+59
-30
lines changed

1 file changed

+59
-30
lines changed

apps/web/src/lib/feedback/components/feedback-popover.tsx

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useState } from "react";
44
import { useForm } from "react-hook-form";
55
import { toast } from "sonner";
6+
import { ClockIcon } from "lucide-react";
67
import {
78
Popover,
89
PopoverContent,
@@ -106,8 +107,11 @@ export function FeedbackPopover() {
106107
);
107108
}
108109

110+
type View = "compose" | "history";
111+
109112
function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
110113
const { entries, isSubmitting, submit } = useFeedback();
114+
const [view, setView] = useState<View>("compose");
111115

112116
const form = useForm<FeedbackFormValues>({
113117
defaultValues: { message: "" },
@@ -124,6 +128,33 @@ function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
124128
});
125129
}
126130

131+
if (view === "history") {
132+
return (
133+
<div className="flex flex-col">
134+
<div
135+
className="max-h-72 overflow-y-auto divide-y"
136+
style={{
137+
maskImage:
138+
"linear-gradient(to bottom, black 80%, transparent 100%)",
139+
}}
140+
>
141+
{entries.map((entry) => (
142+
<FeedbackEntryItem key={entry.id} entry={entry} />
143+
))}
144+
</div>
145+
<div className="border-t px-3 py-2">
146+
<button
147+
type="button"
148+
onClick={() => setView("compose")}
149+
className="text-xs text-muted-foreground/60 hover:text-muted-foreground transition-colors"
150+
>
151+
← Back
152+
</button>
153+
</div>
154+
</div>
155+
);
156+
}
157+
127158
return (
128159
<div className="flex flex-col">
129160
<Form persistKey={PERSIST_KEY} {...form}>
@@ -143,43 +174,41 @@ function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
143174
</FormItem>
144175
)}
145176
/>
146-
<div className="flex justify-end border-t px-3 py-2 gap-2">
147-
{!form.watch("message").trim() && (
148-
<Button
177+
<div className="flex items-center justify-between border-t px-3 py-2">
178+
{entries.length > 0 ? (
179+
<button
149180
type="button"
150-
variant="outline"
181+
onClick={() => setView("history")}
182+
className="flex items-center gap-1.5 text-xs text-muted-foreground/60 hover:text-muted-foreground transition-colors"
183+
>
184+
<ClockIcon className="size-3" />
185+
{entries.length}
186+
</button>
187+
) : (
188+
<span />
189+
)}
190+
<div className="flex gap-2">
191+
{!form.watch("message").trim() && (
192+
<Button
193+
type="button"
194+
variant="outline"
195+
size="sm"
196+
onClick={onClose}
197+
>
198+
Cancel
199+
</Button>
200+
)}
201+
<Button
202+
type="submit"
151203
size="sm"
152-
onClick={onClose}
204+
disabled={isSubmitting || !form.watch("message").trim()}
153205
>
154-
Cancel
206+
{isSubmitting ? <Spinner /> : "Send"}
155207
</Button>
156-
)}
157-
<Button
158-
type="submit"
159-
size="sm"
160-
disabled={isSubmitting || !form.watch("message").trim()}
161-
>
162-
{isSubmitting ? <Spinner /> : "Send"}
163-
</Button>
208+
</div>
164209
</div>
165210
</form>
166211
</Form>
167-
168-
{entries.length > 0 && (
169-
<div className="border-t overflow-hidden">
170-
<div
171-
className="max-h-52 overflow-y-auto divide-y"
172-
style={{
173-
maskImage:
174-
"linear-gradient(to bottom, black 70%, transparent 100%)",
175-
}}
176-
>
177-
{entries.map((entry) => (
178-
<FeedbackEntryItem key={entry.id} entry={entry} />
179-
))}
180-
</div>
181-
</div>
182-
)}
183212
</div>
184213
);
185214
}

0 commit comments

Comments
 (0)