From b06e569e39de7fd48a9529ebce40478f29aee016 Mon Sep 17 00:00:00 2001 From: MehrdadAdabi <126083584+mehrdadAdabi@users.noreply.github.com> Date: Tue, 26 Aug 2025 07:06:52 +0330 Subject: [PATCH] fix: set dynamic dialog conetnt --- .../digital-innovation-page.tsx | 171 ++++++------------ .../process-innovation-page.tsx | 3 +- 2 files changed, 52 insertions(+), 122 deletions(-) diff --git a/app/components/dashboard/project-management/digital-innovation-page.tsx b/app/components/dashboard/project-management/digital-innovation-page.tsx index d7a4afe..9a4364e 100644 --- a/app/components/dashboard/project-management/digital-innovation-page.tsx +++ b/app/components/dashboard/project-management/digital-innovation-page.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useCallback, useRef } from "react"; +import { useState, useEffect, useCallback, useRef, useMemo } from "react"; import { DashboardLayout } from "../layout"; import { Card, CardContent } from "~/components/ui/card"; import { Button } from "~/components/ui/button"; @@ -41,7 +41,6 @@ import { LoaderCircle, } from "lucide-react"; import { CustomBarChart } from "~/components/ui/custom-bar-chart"; -import { color } from "d3"; moment.loadPersian({ usePersianDigits: true }); @@ -74,7 +73,7 @@ interface DigitalInnovationMetrics { // Normalized interface for digital innovation stats interface DigitalInnovationStats { - totalDigitalProjects: number; + // totalDigitalProjects: number; increasedRevenue: number; increasedRevenuePercent: number; reduceCosts: number; @@ -98,6 +97,8 @@ interface ProcessInnovationData { project_status: string; project_rating: string; project_description: string; + total_project: number; + WorkflowID: number; } interface HouseItem { @@ -128,6 +129,7 @@ const columns = [ sortable: true, width: "140px", }, + { key: "details", label: "جزئیات پروژه", sortable: false, width: "140px" }, ]; export function DigitalInnovationPage() { @@ -140,8 +142,9 @@ export function DigitalInnovationPage() { const [totalCount, setTotalCount] = useState(0); const [actualTotalCount, setActualTotalCount] = useState(0); const [statsLoading, setStatsLoading] = useState(false); + const [rating, setRating] = useState([]); + const [dialogInfo, setDialogInfo] = useState(); const [stats, setStats] = useState({ - totalDigitalProjects: 0, increasedRevenue: 0, increasedRevenuePercent: 0, reduceCosts: 0, @@ -173,21 +176,16 @@ export function DigitalInnovationPage() { } }; - // const handleSelectProject = (projectNo: string) => { - // const newSelected = new Set(selectedProjects); - // if (newSelected.has(projectNo)) { - // newSelected.delete(projectNo); - // } else { - // newSelected.add(projectNo); - // } - // setSelectedProjects(newSelected); - // }; - - // const handleProjectDetails = (project: ProcessInnovationData) => { - // console.log(project); - // // setSelectedProjectDetails(project); - // setDetailsDialogOpen(true); - // }; + const handleProjectDetails = (project: ProcessInnovationData) => { + const model: ListItem = { + label: `فرآیند-${project.WorkflowID}`, + development: +project.project_rating, + house: [], + }; + setRating([model]); + setDialogInfo(project); + setDetailsDialogOpen(true); + }; const formatNumber = (value: string | number) => { if (!value) return "0"; @@ -260,9 +258,17 @@ export function DigitalInnovationPage() { OutputFields: [ "project_no", "title", - "project_description", "project_status", "project_rating", + "project_description", + "digital_competence", + "originality_digital_solution", + "digital_puberty_elements", + "digital_capability", + "operational_plan", + "desired_strategy", + "innovation_cost_reduction", + "reduce_costs_percent" ], Sorts: [["start_date", "asc"]], Conditions: [["type_of_innovation", "=", "نوآوری دیجیتال"]], @@ -389,7 +395,7 @@ export function DigitalInnovationPage() { const response = await apiService.select({ ProcessName: "project", OutputFields: ["count(project_no)"], - Conditions: [["type_of_innovation", "=", "نوآوری در فرآیند"]], + Conditions: [["type_of_innovation", "=", "نوآوری دیجیتال"]], }); if (response.state === 0) { @@ -438,11 +444,7 @@ export function DigitalInnovationPage() { } return 0; }; - const normalized: DigitalInnovationStats = { - totalDigitalProjects: parseNum( - payload?.count_innovation_digital_projects - ), increasedRevenue: parseNum(payload?.increased_revenue), increasedRevenuePercent: parseNum(payload?.increased_revenue_percent), reduceCosts: parseNum(payload?.reduce_costs), @@ -465,15 +467,15 @@ export function DigitalInnovationPage() { } }; - const handleRefresh = () => { - fetchingRef.current = false; - setCurrentPage(1); - setProjects([]); - setHasMore(true); - fetchTable(true); - fetchTotalCount(); - fetchStats(); - }; + // const handleRefresh = () => { + // fetchingRef.current = false; + // setCurrentPage(1); + // setProjects([]); + // setHasMore(true); + // fetchTable(true); + // fetchTotalCount(); + // fetchStats(); + // }; const formatCurrency = (amount: string | number) => { if (!amount) return "0 ریال"; @@ -485,67 +487,10 @@ export function DigitalInnovationPage() { return new Intl.NumberFormat("fa-IR").format(numericAmount) + " ریال"; }; - // const formatPercentage = (value: string | number) => { - // if (!value) return "0%"; - // const numericValue = typeof value === "string" ? parseFloat(value) : value; - // if (isNaN(numericValue)) return "0%"; - // return `${numericValue.toFixed(1)}%`; - // }; - - // const getStatusColor = (status: string) => { - // switch (status?.toLowerCase()) { - // case "فعال": - // return "#3AEA83"; - // case "متوقف": - // return "#F76276"; - // case "تکمیل شده": - // return "#32CD32"; - // default: - // return "#6B7280"; - // } - // }; - - // const getRatingColor = (rating: string) => { - // const ratingNum = parseFloat(rating); - // if (isNaN(ratingNum)) return "#6B7280"; - - // if (ratingNum >= 8) return "#3AEA83"; - // if (ratingNum >= 6) return "#69C8EA"; - // if (ratingNum >= 4) return "#FFD700"; - // return "#F76276"; - // }; - - const [list, setList] = useState([ - { - label: "فرآیند1", - development: 40, - house: [], - }, - { - label: "فرآیند2", - development: 30, - house: [], - }, - { - label: "فرآیند3", - development: 40, - house: [], - }, - { - label: "فرآیند4", - development: 50, - house: [], - }, - { - label: "فرآیند5", - development: 91.6, - house: [], - }, - ]); - const renderProgress = () => { + const renderProgress = useMemo(() => { const total = 10; - for (let i = 0; i < list.length; i++) { - const currentElm = list[i]; + for (let i = 0; i < rating.length; i++) { + const currentElm = rating[i]; currentElm.house = []; const greenBoxes = Math.floor((total * currentElm.development) / 100); const partialPercent = @@ -561,18 +506,14 @@ export function DigitalInnovationPage() { index: greenBoxes + 1, style: `linear-gradient( to right, - lch(87 118.17 147.55) 0%, - lch(87 118.17 147.55) ${partialPercent * 100}%, + oklch(76.5% 0.177 163.223) 0%, + oklch(76.5% 0.177 163.223) ${partialPercent * 100}%, oklch(55.1% 0.027 264.364) ${partialPercent * 100}%, oklch(55.1% 0.027 264.364) 100% )`, }); } - }; - - useEffect(() => { - renderProgress(); - }, []); + }, [rating]); const renderCellContent = (item: any, column: any) => { const value = item[column.key as keyof ProcessInnovationData]; @@ -591,7 +532,7 @@ export function DigitalInnovationPage() {