avatar upload fix
This commit is contained in:
parent
feb2f5edda
commit
82397d63a7
@ -85,7 +85,6 @@ const Profile = () => {
|
|||||||
const [file, setFile] = useState(null);
|
const [file, setFile] = useState(null);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
const fileSelector = useRef();
|
|
||||||
const usernameRef = useRef();
|
const usernameRef = useRef();
|
||||||
const displayNameRef = useRef();
|
const displayNameRef = useRef();
|
||||||
const currPassRef = useRef();
|
const currPassRef = useRef();
|
||||||
@ -93,8 +92,8 @@ const Profile = () => {
|
|||||||
const newPassRepeatRef = useRef();
|
const newPassRepeatRef = useRef();
|
||||||
|
|
||||||
const submit = async ({ target: button }) => {
|
const submit = async ({ target: button }) => {
|
||||||
button.disabled = true;
|
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
button.disabled = true;
|
||||||
|
|
||||||
const body = new FormData();
|
const body = new FormData();
|
||||||
body.set('file', file, file.name);
|
body.set('file', file, file.name);
|
||||||
@ -102,7 +101,7 @@ const Profile = () => {
|
|||||||
|
|
||||||
const response = await post('/api/user/avatar', body, { headers: null });
|
const response = await post('/api/user/avatar', body, { headers: null });
|
||||||
if (!response.success) setError(response.message);
|
if (!response.success) setError(response.message);
|
||||||
else fileSelector.current.value = null;
|
else setFile(null);
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -146,7 +145,7 @@ const Profile = () => {
|
|||||||
<p><b>Change Profile Picture</b></p>
|
<p><b>Change Profile Picture</b></p>
|
||||||
<form className="f-g f-b0">
|
<form className="f-g f-b0">
|
||||||
<FileSelector cb={setFile} />
|
<FileSelector cb={setFile} />
|
||||||
<button onClick={submit} className="button primary mt-3">Submit</button>
|
<button type='button' onClick={submit} className="button primary mt-3">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user