Commit 9f40704e authored by Balasuriya D.A.M.'s avatar Balasuriya D.A.M.

Profile Picture Upload (Cloudianry)

parent dcd5e09b
...@@ -77,4 +77,4 @@ const Login = () => { ...@@ -77,4 +77,4 @@ const Login = () => {
); );
} }
export default Login; export default Login;
\ No newline at end of file \ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import { Button, FormControl, FormLabel, Input, InputGroup, InputRightElement, VStack } from "@chakra-ui/react"; import { Button, FormControl, FormLabel, Input, InputGroup, InputRightElement, VStack } from "@chakra-ui/react";
import React, { useState } from "react"; import React, { useState } from "react";
import { useToast } from "@chakra-ui/react";
const Signup = () => { const Signup = () => {
...@@ -14,12 +15,58 @@ const Signup = () => { ...@@ -14,12 +15,58 @@ const Signup = () => {
const [confirmpassword, setConfirmpassword] = useState(); const [confirmpassword, setConfirmpassword] = useState();
const [password, setPassword] = useState(); const [password, setPassword] = useState();
const [pic, setPic] = useState(); const [pic, setPic] = useState();
const [loading, setLoading] = useState(false);
const toast = useToast();
const handleClick = () => setShow(!show); const handleClick = () => setShow(!show);
const postDetails = (pics) => { }; const postDetails = (pics) => {
setLoading(true);
const submitHandler = () => { }; if (pics === undefined) {
toast({
title: "Please Select an Image!",
status: "warning",
duration: 5000, //How long message is displaying
isClosable: true,
position:"bottom",
});
return;
}
if (pics.type === "image/jpeg" || pics.type === "image/png") {
const data = new FormData();
data.append("file", pics);
data.append("upload_preset", "chat-app");
data.append("cloud_name", "minocode");
//fetch("const data = new FormData();");
fetch("https://api.cloudinary.com/v1_1/minocode/image/upload", {
method: "post",
body: data,
}).then((res) => res.json())
.then(data => {
setPic(data.url.toString());
setLoading(false);
})
.catch((err) => {
console.log(err);
setLoading(false);
});
} else {
toast({
title: "Please Select an Image!",
status: "warning",
duration: 5000,
isClosable: true,
position: "bottom",
});
setLoading(false);
return;
}
};
const submitHandler = () => {
};
return ( return (
//Use vstack to allign verticaly //Use vstack to allign verticaly
...@@ -97,6 +144,7 @@ const Signup = () => { ...@@ -97,6 +144,7 @@ const Signup = () => {
width="100%" width="100%"
style={{ marginTop: 15 }} style={{ marginTop: 15 }}
onClick={submitHandler} onClick={submitHandler}
isLoading={loading}
> >
Sign Up Sign Up
...@@ -108,4 +156,4 @@ const Signup = () => { ...@@ -108,4 +156,4 @@ const Signup = () => {
); );
} }
export default Signup; export default Signup;
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment