Skip to content

Commit c5847bf

Browse files
committed
Quota max value is not updated when quota is changed
#80
1 parent c5c3da3 commit c5847bf

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/components/ChangeQuota.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
Typography,
1212
} from '@mui/material';
1313
import { 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';
1516
import toast from 'react-hot-toast';
1617

1718
import { 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

Comments
 (0)