47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
"use client"
|
|
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
|
|
|
import Button from "@/components/TempDesignSystem/Button"
|
|
import { toast } from "@/components/TempDesignSystem/Toasts"
|
|
|
|
import styles from "./copybutton.module.css"
|
|
|
|
import type { CopyButtonProps } from "@/types/components/myPages/membership"
|
|
|
|
export default function CopyButton({ membershipNumber }: CopyButtonProps) {
|
|
const intl = useIntl()
|
|
|
|
function handleCopy() {
|
|
try {
|
|
navigator.clipboard.writeText(membershipNumber)
|
|
toast.success(
|
|
intl.formatMessage({
|
|
defaultMessage: "Membership ID copied to clipboard",
|
|
})
|
|
)
|
|
} catch {
|
|
toast.error(
|
|
intl.formatMessage({
|
|
defaultMessage: "Failed to copy",
|
|
})
|
|
)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Button
|
|
onClick={handleCopy}
|
|
className={styles.button}
|
|
type="button"
|
|
variant="icon"
|
|
size="small"
|
|
intent="tertiary"
|
|
>
|
|
<MaterialIcon icon="content_copy" color="CurrentColor" />
|
|
</Button>
|
|
)
|
|
}
|