"use client"; import { Button } from "@ui/components/button"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@ui/components/dialog"; import { useMemo, useRef } from "react"; import type { ReactCropperElement } from "react-cropper"; import Cropper from "react-cropper"; export function CropImageDialog({ image, open, onOpenChange, onCrop, }: { image: File | null; open: boolean; onOpenChange: (open: boolean) => void; onCrop: (croppedImage: Blob | null) => void; }) { const cropperRef = useRef(null); const getCroppedImage = async () => { const cropper = cropperRef.current?.cropper; const imageBlob = await new Promise((resolve) => { cropper ?.getCroppedCanvas({ maxWidth: 256, maxHeight: 256, }) .toBlob(resolve); }); return imageBlob; }; const imageSrc = useMemo( () => image && URL.createObjectURL(image), [image], ); return (
{imageSrc && ( )}
); }