diff --git a/@/components/ui/input.tsx b/@/components/ui/input.tsx new file mode 100644 index 000000000..677d05fd6 --- /dev/null +++ b/@/components/ui/input.tsx @@ -0,0 +1,25 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +export interface InputProps + extends React.InputHTMLAttributes {} + +const Input = React.forwardRef( + ({ className, type, ...props }, ref) => { + return ( + + ) + } +) +Input.displayName = "Input" + +export { Input } diff --git a/app/sos/page.tsx b/app/sos/page.tsx new file mode 100644 index 000000000..731f1051f --- /dev/null +++ b/app/sos/page.tsx @@ -0,0 +1,101 @@ +// make a page where you can select from garment types, collection types and numbers to create a copyable name +"use client" + +import { Input } from "@/components/ui/input"; +import { Combox } from "components/combox"; +import { ProductSKUs } from "components/product/sku-generator"; +import { collectionsSKUs, garmentHandleKeys } from "constants/sku"; +import { capitalizeFirstLetter, copyText, getKeyByValue } from "lib/helpers/actions"; +import { useEffect, useState } from "react"; + +// type SKUSelectorState = { +// garment?: keyof typeof garmentHandleKeys, +// collection?: keyof typeof collectionsSKUs, +// }; + +export default async function NewProductHelpPage() { + // const [open, setOpen] = useState(false) + const [collection, setCollection] = useState(null) + const [garment, setGarment] = useState(null) + const [title, setTitle] = useState(null) + const [number, setNumber] = useState(null) + + useEffect(() => { + const title = createTitle() + console.log("🍓🍋🍊 title", title); + + }, [collection, garment]) + + const garmentValues = Object.keys(garmentHandleKeys) + const collectionValues = Object.keys(collectionsSKUs) + + const optionsMapper = (keys: {}, values: string[]) => { + return values.map(value => { + return { + key: keys[value as keyof typeof keys], + label: value, + } + }) + } + + const garmentOptions = optionsMapper(garmentHandleKeys, garmentValues); + const collectionOptions = optionsMapper(collectionsSKUs, collectionValues); + + const createTitle = () => { + let collectionMapper = getKeyByValue(collectionsSKUs, collection) + if (collectionMapper) collectionMapper = capitalizeFirstLetter(collectionMapper) + let garmentMapper = getKeyByValue(garmentHandleKeys, garment) + if (garmentMapper) garmentMapper = capitalizeFirstLetter(garmentMapper) + setTitle(`${collectionMapper}scape No.${number} ${garmentMapper}`) + } + + + + return ( +
+
+
+

New Product Creator

+
+
+ setCollection(key as keyof typeof collectionsSKUs)} + currentKey={collection || null} + /> +
+
+ setNumber(e.target.value)} + /> +
+
+ setGarment(key as keyof typeof garmentHandleKeys)} + currentKey={garment || null} + /> +
+ + {garment && collection && number && title && + <> +
+
copyText(title)} + > + {title} +
+
+
+ +
+ + } +
+
+ ) +} \ No newline at end of file diff --git a/components/combox.tsx b/components/combox.tsx index 5fae5c7ec..c7026143d 100644 --- a/components/combox.tsx +++ b/components/combox.tsx @@ -23,9 +23,17 @@ type Option = { label: string, } -export function Combox({options}: {options: Option[]}) { +export function Combox( + { + options, + currentKey, + onShow, + }: { + options: Option[], + currentKey: string | null, + onShow: ((key: string) => void), + }) { const [open, setOpen] = useState(false) - const [currentKey, setCurrentKey] = useState(null) return ( @@ -34,15 +42,15 @@ export function Combox({options}: {options: Option[]}) { variant="outline" role="combobox" aria-expanded={open} - className="w-[200px] justify-between" + className="w-[200px] justify-between truncate text-ellipsis" > {currentKey ? options.find((option) => option.key === currentKey)?.label : "Select option..."} - - +

+ No option found. @@ -51,8 +59,9 @@ export function Combox({options}: {options: Option[]}) { { - setCurrentKey(option.key) + // setCurrentKey(option.key) setOpen(false) + onShow(option.key) }} > (null); - const triggerCopyMessage = async (e: MouseEvent, i: number) => { - copyText(e.target.value) + const triggerCopyMessage = async (i: number, SKU: string) => { + copyText(SKU) console.log("copyMessageState", copyMessageState); setCopyMessageState(i); @@ -19,22 +24,18 @@ export function ProductSKUs(productInfo: {productTitle: string}) { setTimeout(() => setCopyMessageState(null), 2500) } - function copyText(text: string) { - navigator.clipboard.writeText(text); - } - return ( <>
-

{productInfo.productTitle}

+ { !noTitle &&

{productTitle}

} {/* {copyMessageState} */} {SKUs?.map((SKU, index) => { return (
triggerCopyMessage(e, index)} + onClick={() => triggerCopyMessage(index, SKU)} className={clsx( [ "cursor-pointer w-full border py-2 px-2 rounded", diff --git a/lib/helpers/actions.tsx b/lib/helpers/actions.tsx new file mode 100644 index 000000000..f188ef3d3 --- /dev/null +++ b/lib/helpers/actions.tsx @@ -0,0 +1,11 @@ +export function copyText(text: string) { + navigator.clipboard.writeText(text); +} + +export function capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1); +} + +export function getKeyByValue(object, value) { + return Object.keys(object).find(key => object[key] === value); +}