-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add step 4 images upload with cloudinary
- Loading branch information
Showing
5 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
"use client"; | ||
|
||
import { CldUploadWidget } from "next-cloudinary"; | ||
import { useCallback } from "react"; | ||
import { TbPhotoPlus } from "react-icons/tb"; | ||
import Image from "next/image"; | ||
|
||
declare global { | ||
var cloudinary: any; | ||
} | ||
|
||
interface ImageUploadProps { | ||
onChange: (value: string) => void; | ||
value: string; | ||
} | ||
|
||
const ImageUpload: React.FC<ImageUploadProps> = ({ onChange, value }) => { | ||
const handleUpload = useCallback( | ||
(result: any) => { | ||
onChange(result.info.secure_url); | ||
}, | ||
[onChange] | ||
); | ||
|
||
return ( | ||
<CldUploadWidget | ||
onUpload={handleUpload} | ||
uploadPreset="Airbnb-clone" | ||
options={{ | ||
maxFiles: 1, | ||
styles: { | ||
palette: { | ||
window: "#F5F5F5", | ||
sourceBg: "#FFFFFF", | ||
windowBorder: "#90a0b3", | ||
tabIcon: "#69778A", | ||
inactiveTabIcon: "#69778A", | ||
menuIcons: "#69778A", | ||
link: "#F43F5E", | ||
action: "#8F5DA5", | ||
inProgress: "#0194c7", | ||
complete: "#53ad9d", | ||
error: "#c43737", | ||
textDark: "#90A0B3", | ||
textLight: "#FFFFFF", | ||
}, | ||
frame: { | ||
background: "#67676700", | ||
}, | ||
}, | ||
}} | ||
> | ||
{({ open }) => { | ||
return ( | ||
<div | ||
onClick={() => open?.()} | ||
className=" | ||
relative | ||
cursor-pointer | ||
hover:opacity-70 | ||
transition | ||
border-dashed | ||
border-2 | ||
p-20 | ||
border-neutral-300 | ||
flex | ||
flex-col | ||
justify-center | ||
items-center | ||
gap-4 | ||
text-neutral-600 | ||
" | ||
> | ||
<TbPhotoPlus size={50} /> | ||
<div className="font-semibold text-lg">Click to upload a photo</div> | ||
{value && ( | ||
<div className="absolute inset-0 w-full h-full"> | ||
<Image | ||
alt="Uploaded image" | ||
fill | ||
style={{ objectFit: "cover" }} | ||
src={value} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}} | ||
</CldUploadWidget> | ||
); | ||
}; | ||
|
||
export default ImageUpload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters