feat: refactor feedback service methods and enhance feedback user details in UI
This commit is contained in:
parent
fdfa0bf6c7
commit
daeeb3eb52
@ -41,18 +41,6 @@ public function __construct()
|
||||
$this->sanitizer = new HtmlSanitizer($config);
|
||||
}
|
||||
|
||||
public function paginated(User $user, int $perPage = 25, string $search = '', ?string $type = null, ?string $status = null): LengthAwarePaginator
|
||||
{
|
||||
return Feedback::query()
|
||||
->where('user_id', $user->id)
|
||||
->with('handler.profile')
|
||||
->when($search, fn($q) => $q->where('subject', 'like', "%{$search}%"))
|
||||
->when($type, fn($q) => $q->where('type', $type))
|
||||
->when($status, fn($q) => $q->where('status', $status))
|
||||
->latest()
|
||||
->paginate($perPage);
|
||||
}
|
||||
|
||||
public function pendingCount(User $user): int
|
||||
{
|
||||
return Feedback::query()
|
||||
@ -61,6 +49,18 @@ public function pendingCount(User $user): int
|
||||
->count();
|
||||
}
|
||||
|
||||
public function paginated(User $user, int $perPage = 25, string $search = '', ?string $type = null, ?string $status = null): LengthAwarePaginator
|
||||
{
|
||||
return Feedback::query()
|
||||
->where('user_id', $user->id)
|
||||
->with(['user.profile', 'handler.profile'])
|
||||
->when($search, fn ($q) => $q->where('subject', 'like', "%{$search}%"))
|
||||
->when($type, fn ($q) => $q->where('type', $type))
|
||||
->when($status, fn ($q) => $q->where('status', $status))
|
||||
->latest()
|
||||
->paginate($perPage);
|
||||
}
|
||||
|
||||
public function create(User $user, array $data): Feedback
|
||||
{
|
||||
return Feedback::create([
|
||||
|
||||
@ -31,13 +31,6 @@ export const FeedbackStatusVariants: Record<
|
||||
resolved: 'default',
|
||||
};
|
||||
|
||||
function stripHtml(html: string): string {
|
||||
return html
|
||||
.replace(/<[^>]+>/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function createFeedbackColumns(
|
||||
params: CreateColumnsParams,
|
||||
): ColumnDef<Feedback>[] {
|
||||
@ -55,7 +48,7 @@ export function createFeedbackColumns(
|
||||
return [
|
||||
{
|
||||
accessorKey: 'subject',
|
||||
header: () => <span>Subjek</span>
|
||||
header: () => <span>Subjek</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'type',
|
||||
@ -93,6 +86,11 @@ export function createFeedbackColumns(
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'user.profile.full_name',
|
||||
header: () => <span>Dibuat Oleh</span>,
|
||||
cell: ({ row }) => row.original.user?.profile?.full_name ?? '-',
|
||||
},
|
||||
{
|
||||
accessorKey: 'handler.profile.full_name',
|
||||
header: () => <span>Ditindaklanjuti Oleh</span>,
|
||||
|
||||
@ -358,12 +358,12 @@ function ViewDetailDialog({
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="flex max-h-[85vh] flex-col overflow-hidden sm:max-w-3xl">
|
||||
<DialogHeader>
|
||||
<DialogHeader className="shrink-0">
|
||||
<DialogTitle>Detail Kritik dan Saran</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{feedback && (
|
||||
<div className="grid gap-4 overflow-y-auto">
|
||||
<div className="grid min-h-0 flex-1 gap-4 overflow-y-auto">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Badge variant="outline">
|
||||
{FeedbackTypeLabels[feedback.type]}
|
||||
@ -391,6 +391,13 @@ function ViewDetailDialog({
|
||||
<p className="font-medium">{feedback.subject}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1">
|
||||
<Label className="text-muted-foreground">
|
||||
Dibuat Oleh
|
||||
</Label>
|
||||
<p>{feedback.user?.profile?.full_name ?? '-'}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1">
|
||||
<Label className="text-muted-foreground">
|
||||
Ditindaklanjuti Oleh
|
||||
|
||||
@ -23,8 +23,15 @@ export type FeedbackHandler = {
|
||||
profile: { full_name: string } | null;
|
||||
};
|
||||
|
||||
export type FeedbackUser = {
|
||||
id: number;
|
||||
profile: { full_name: string } | null;
|
||||
};
|
||||
|
||||
export type Feedback = {
|
||||
id: number;
|
||||
user_id: number;
|
||||
user: FeedbackUser | null;
|
||||
type: FeedbackTypeValue;
|
||||
subject: string;
|
||||
message: string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user