feat: mutate profile page if successful change

This commit is contained in:
Kentai Radiquum 2024-09-20 14:35:51 +05:00
parent 61eb728442
commit 2d200b84f2
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
4 changed files with 17 additions and 2 deletions

View file

@ -3,6 +3,7 @@
import { Button, Modal, Textarea } from "flowbite-react";
import { ENDPOINTS } from "#/api/config";
import { useEffect, useState } from "react";
import { useSWRConfig } from "swr";
export const ProfileEditStatusModal = (props: {
isOpen: boolean;
@ -10,10 +11,12 @@ export const ProfileEditStatusModal = (props: {
token: string;
status: string;
setStatus: (status: string) => void;
profile_id: number;
}) => {
const [loading, setLoading] = useState(false);
const [_status, _setStatus] = useState("");
const [_stringLength, _setStringLength] = useState(0);
const { mutate } = useSWRConfig();
useEffect(() => {
_setStatus(props.status);
@ -38,6 +41,9 @@ export const ProfileEditStatusModal = (props: {
})
.then((res) => {
if (res.ok) {
mutate(
`${ENDPOINTS.user.profile}/${props.profile_id}?token=${props.token}`
);
setLoading(false);
props.setStatus(_status);
props.setIsOpen(false);