diff --git a/components/product/sku-generator.tsx b/components/product/sku-generator.tsx index 6ffbfffc2..ef2254823 100644 --- a/components/product/sku-generator.tsx +++ b/components/product/sku-generator.tsx @@ -1,24 +1,49 @@ 'use client' +import clsx from "clsx"; import { createProductSKUs } from "lib/helpers/skus"; +import { useState } from "react"; export function ProductSKUs(productInfo: {productTitle: string}) { const SKUs = createProductSKUs(productInfo.productTitle) + const [copyMessageState, setCopyMessageState] = useState< number | null >(null); + + const triggerCopyMessage = async (e: MouseEvent, i: number) => { + copyText(e.target.value) + + console.log("copyMessageState", copyMessageState); + setCopyMessageState(i); + console.log("copyMessageState", copyMessageState); + + setTimeout(() => setCopyMessageState(null), 2500) + } - function copyText(e) { - navigator.clipboard.writeText(e.target.value); + function copyText(text: string) { + navigator.clipboard.writeText(text); } return ( <>
-
-
- {SKUs?.map(SKU => { +
+
+

{productInfo.productTitle}

+ {/* {copyMessageState} */} + {SKUs?.map((SKU, index) => { return ( -
- +
+
triggerCopyMessage(e, index)} + className={clsx( + [ + "cursor-pointer w-full border py-2 px-2 rounded", + { 'border-green-500': (copyMessageState === index) }, + ] + )} + > + {SKU} +
) })} diff --git a/constants/sku.tsx b/constants/sku.tsx index fcc5476c3..a7911a987 100644 --- a/constants/sku.tsx +++ b/constants/sku.tsx @@ -58,6 +58,7 @@ export const customisationSKUs = { }; export const sizeSKUs = { + xxs: 'XXS', xs: 'XS', s: 'S', m: 'M',