Skip to content

Commit

Permalink
refactor:button export for types
Browse files Browse the repository at this point in the history
  • Loading branch information
ademsuslu committed Nov 15, 2024
1 parent e23a874 commit 7db46ad
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/(dashboard)/customer/edit/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function CustomerDetails({
return <div className="flex flex-col justify-between items-center gap-2">
<div className="flex w-full justify-between gap-2">
<Link href={"/customer"} className={buttonVariants({})}>Back</Link>
<ButtonsExport data={data} />
<ButtonsExport type="customer" data={data} />
</div>
<div className="w-full">
<CustomerEditForm data={data}/>
Expand Down
2 changes: 1 addition & 1 deletion app/(dashboard)/customer/reminder/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function CustomerCreateReminder({
return <div className="flex flex-col justify-between items-center gap-2">
<div className="flex w-full justify-between gap-2">
<Link href={"/customer/reminder"} className={buttonVariants({})}>Back</Link>
<ButtonsExport type="reminder" data={data?.data} />
<ButtonsExport type="reminder" />
</div>
<div className="w-full">
<div className="flex flex-col">
Expand Down
3 changes: 1 addition & 2 deletions app/(dashboard)/customer/reminder/edit/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,7 +15,7 @@ export default async function CustomerDetails({
return <div className="flex flex-col justify-between items-center gap-2">
<div className="flex w-full justify-between gap-2">
<Link href={"/customer/reminder"} className={buttonVariants({})}>Back</Link>
<ButtonsExport data={data?.data} type="reminder" />
<ButtonsExport type="reminder" />
</div>
<div className="w-full">
<ReminderEditForm data={data?.data} />
Expand Down
4 changes: 2 additions & 2 deletions components/shared/detay/buttons-export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TiTick } from "react-icons/ti";


type ButtonsExportProps = {
data: Customer
data?: Customer
type?: "reminder" | "customer"
};
const ButtonsExport: React.FC<ButtonsExportProps> = ({ data, type }) => {
Expand All @@ -21,7 +21,7 @@ const ButtonsExport: React.FC<ButtonsExportProps> = ({ 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',
Expand Down
14 changes: 7 additions & 7 deletions utils/ExportToCSV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ""
]
];

Expand Down

0 comments on commit 7db46ad

Please sign in to comment.