From 7db46ad4ad68d1ddf7ac3db67543a3ed779f9018 Mon Sep 17 00:00:00 2001 From: ademsuslu Date: Fri, 15 Nov 2024 19:34:12 +0300 Subject: [PATCH] refactor:button export for types --- app/(dashboard)/customer/edit/[id]/page.tsx | 2 +- app/(dashboard)/customer/reminder/[id]/page.tsx | 2 +- .../customer/reminder/edit/[id]/page.tsx | 3 +-- components/shared/detay/buttons-export.tsx | 4 ++-- utils/ExportToCSV.ts | 14 +++++++------- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/(dashboard)/customer/edit/[id]/page.tsx b/app/(dashboard)/customer/edit/[id]/page.tsx index f83e75b..1ec96c8 100644 --- a/app/(dashboard)/customer/edit/[id]/page.tsx +++ b/app/(dashboard)/customer/edit/[id]/page.tsx @@ -14,7 +14,7 @@ export default async function CustomerDetails({ return
Back - +
diff --git a/app/(dashboard)/customer/reminder/[id]/page.tsx b/app/(dashboard)/customer/reminder/[id]/page.tsx index c13c086..0e0c9b4 100644 --- a/app/(dashboard)/customer/reminder/[id]/page.tsx +++ b/app/(dashboard)/customer/reminder/[id]/page.tsx @@ -14,7 +14,7 @@ export default async function CustomerCreateReminder({ return
Back - +
diff --git a/app/(dashboard)/customer/reminder/edit/[id]/page.tsx b/app/(dashboard)/customer/reminder/edit/[id]/page.tsx index 5fde11f..aa185a3 100644 --- a/app/(dashboard)/customer/reminder/edit/[id]/page.tsx +++ b/app/(dashboard)/customer/reminder/edit/[id]/page.tsx @@ -1,7 +1,6 @@ import ButtonsExport from "@/components/shared/detay/buttons-export" import { buttonVariants } from "@/components/ui/button" import Link from "next/link" -import CustomerEditForm from "@/components/shared/customer-edit-form" import ReminderEditForm from "@/components/shared/reminder/reminder-edit-form" export default async function CustomerDetails({ params, @@ -16,7 +15,7 @@ export default async function CustomerDetails({ return
Back - +
diff --git a/components/shared/detay/buttons-export.tsx b/components/shared/detay/buttons-export.tsx index a422aea..00142a1 100644 --- a/components/shared/detay/buttons-export.tsx +++ b/components/shared/detay/buttons-export.tsx @@ -11,7 +11,7 @@ import { TiTick } from "react-icons/ti"; type ButtonsExportProps = { - data: Customer + data?: Customer type?: "reminder" | "customer" }; const ButtonsExport: React.FC = ({ data, type }) => { @@ -21,7 +21,7 @@ const ButtonsExport: React.FC = ({ data, type }) => { ExportToExcel(data); }; const handleDelete = async () => { - const url = type !== 'reminder' ? ` ${"https://crm-backend-production-e80f.up.railway.app/api"}/customers/${data._id} ` : ` ${"https://crm-backend-production-e80f.up.railway.app/api"}/reminder/${data._id}` + const url = type !== 'reminder' ? ` ${"https://crm-backend-production-e80f.up.railway.app/api"}/customers/${data?._id} ` : ` ${"https://crm-backend-production-e80f.up.railway.app/api"}/reminder/${data?._id}` try { const response = await fetch(`${url}`, { method: 'DELETE', diff --git a/utils/ExportToCSV.ts b/utils/ExportToCSV.ts index 08198de..24f3efc 100644 --- a/utils/ExportToCSV.ts +++ b/utils/ExportToCSV.ts @@ -3,18 +3,18 @@ import * as XLSX from "xlsx"; import { Customer } from "@/types/customer/model"; -export const ExportToExcel = (data: Customer) => { +export const ExportToExcel = (data?: Customer) => { const headers = ["Adı", "Soyadı", "Cinsiyet", "Müşteri Segmenti", "Telefon", "E-posta"]; // Müşteri verilerini tablo satırı olarak düzenliyoruz const rows = [ [ - data.ad, - data.soyad, - data.cinsiyet, - data.segmentasyon?.musteri_segmenti || "", - data.iletisim_bilgileri?.telefon || "", - data.iletisim_bilgileri?.email || "" + data?.ad, + data?.soyad, + data?.cinsiyet, + data?.segmentasyon?.musteri_segmenti || "", + data?.iletisim_bilgileri?.telefon || "", + data?.iletisim_bilgileri?.email || "" ] ];