@@ -11,7 +11,8 @@ import {
1111 Typography ,
1212} from '@mui/material' ;
1313import { useMutation , useQueryClient } from '@tanstack/react-query' ;
14- import React , { useState } from 'react' ;
14+ import AuthContext from 'context/authContext' ;
15+ import React , { useContext , useState } from 'react' ;
1516import toast from 'react-hot-toast' ;
1617
1718import { changeQuota } from '../api/api' ;
@@ -27,6 +28,7 @@ export const ChangeQuota = ({ id, quota }: ChangeQuotaProps) => {
2728 const currentQuota = + formatBytes ( quota , 2 ) ;
2829 const [ newQuota , setNewQuota ] = useState ( currentQuota ) ;
2930 const [ expanded , setExpanded ] = useState ( false ) ;
31+ const { user, setUser } = useContext ( AuthContext ) ;
3032
3133 const queryClient = useQueryClient ( ) ;
3234
@@ -44,10 +46,17 @@ export const ChangeQuota = ({ id, quota }: ChangeQuotaProps) => {
4446 } ,
4547 } ) ;
4648
47- const handleSubmit = ( event : React . FormEvent < HTMLFormElement > ) => {
48- event . preventDefault ( ) ;
49- changeQuotaMutation . mutate ( { id, quota : convertToBytes ( newQuota ) } ) ;
50- } ;
49+ const handleSubmit = ( event : React . FormEvent < HTMLFormElement > ) => {
50+ event . preventDefault ( ) ;
51+ const updatedQuota = convertToBytes ( newQuota ) ;
52+ changeQuotaMutation . mutate ( { id, quota : updatedQuota } , {
53+ onSuccess : ( ) => {
54+ if ( user ) {
55+ setUser ( { ...user , quota : updatedQuota } ) ;
56+ }
57+ } ,
58+ } ) ;
59+ } ;
5160 const handleCancel = ( ) => {
5261 setNewQuota ( currentQuota ) ;
5362 setExpanded ( false ) ;
0 commit comments