2025-12-16 17:10:14 +09:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import {
|
|
|
|
|
ExclamationCircleIcon,
|
|
|
|
|
CreditCardIcon,
|
|
|
|
|
ClockIcon,
|
|
|
|
|
SparklesIcon,
|
2025-12-23 17:53:08 +09:00
|
|
|
IdentificationIcon,
|
2025-12-16 17:10:14 +09:00
|
|
|
} from "@heroicons/react/24/outline";
|
|
|
|
|
import type { TaskTone } from "../components/TaskCard";
|
2025-12-23 17:53:08 +09:00
|
|
|
import type {
|
|
|
|
|
DashboardTask as DomainDashboardTask,
|
|
|
|
|
DashboardTaskType,
|
|
|
|
|
} from "@customer-portal/domain/dashboard";
|
|
|
|
|
import { useMeStatus } from "./useMeStatus";
|
2025-12-16 17:10:14 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Task type for dashboard actions
|
|
|
|
|
*/
|
2025-12-23 17:53:08 +09:00
|
|
|
export type { DashboardTaskType };
|
2025-12-16 17:10:14 +09:00
|
|
|
|
2025-12-23 17:53:08 +09:00
|
|
|
export interface DashboardTask extends DomainDashboardTask {
|
2025-12-16 17:10:14 +09:00
|
|
|
tone: TaskTone;
|
|
|
|
|
icon: React.ComponentType<React.SVGProps<SVGSVGElement>>;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 17:53:08 +09:00
|
|
|
const TASK_ICONS: Record<DashboardTaskType, DashboardTask["icon"]> = {
|
|
|
|
|
invoice: ExclamationCircleIcon,
|
|
|
|
|
payment_method: CreditCardIcon,
|
|
|
|
|
order: ClockIcon,
|
|
|
|
|
internet_eligibility: ClockIcon,
|
|
|
|
|
id_verification: IdentificationIcon,
|
|
|
|
|
onboarding: SparklesIcon,
|
|
|
|
|
};
|
2025-12-16 17:10:14 +09:00
|
|
|
|
|
|
|
|
export interface UseDashboardTasksResult {
|
|
|
|
|
tasks: DashboardTask[];
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
hasError: boolean;
|
|
|
|
|
taskCount: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-23 17:53:08 +09:00
|
|
|
* Hook to return prioritized dashboard tasks computed by the BFF.
|
2025-12-16 17:10:14 +09:00
|
|
|
*/
|
|
|
|
|
export function useDashboardTasks(): UseDashboardTasksResult {
|
2025-12-23 17:53:08 +09:00
|
|
|
const { data, isLoading, error } = useMeStatus();
|
|
|
|
|
|
|
|
|
|
const tasks = useMemo<DashboardTask[]>(() => {
|
|
|
|
|
const raw = data?.tasks ?? [];
|
|
|
|
|
return raw.map(task => ({
|
|
|
|
|
...task,
|
|
|
|
|
// Default to neutral when undefined (shouldn't happen due to domain validation)
|
|
|
|
|
tone: (task.tone ?? "neutral") as TaskTone,
|
|
|
|
|
icon: TASK_ICONS[task.type] ?? SparklesIcon,
|
|
|
|
|
}));
|
|
|
|
|
}, [data?.tasks]);
|
2025-12-16 17:10:14 +09:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
tasks,
|
2025-12-23 17:53:08 +09:00
|
|
|
isLoading,
|
|
|
|
|
hasError: Boolean(error),
|
2025-12-16 17:10:14 +09:00
|
|
|
taskCount: tasks.length,
|
|
|
|
|
};
|
|
|
|
|
}
|