style(dashboard-v2): improve code readability

This commit is contained in:
Michał Leszczyk 2022-03-08 09:37:24 +01:00
parent 623a4b816b
commit a5327d00f3
No known key found for this signature in database
GPG Key ID: FA123CA8BAA2FBF4
1 changed files with 8 additions and 4 deletions

View File

@ -13,16 +13,20 @@ import { UsageGraph } from "./UsageGraph";
const useUsageData = () => {
const { user } = useUser();
const { activePlan, error } = useActivePlan(user);
const [loading, setLoading] = useState(true);
const { data: stats, error: statsError } = useSWR("user/stats");
const [loading, setLoading] = useState(true);
const [usage, setUsage] = useState({});
const hasError = error || statsError;
const hasData = activePlan && stats;
useEffect(() => {
if ((activePlan && stats) || error || statsError) {
if (hasData || hasError) {
setLoading(false);
}
if (activePlan && stats && !error && !statsError) {
if (hasData && !hasError) {
setUsage({
filesUsed: stats?.numUploads,
filesLimit: activePlan?.limits?.maxNumberUploads,
@ -30,7 +34,7 @@ const useUsageData = () => {
storageLimit: activePlan?.limits?.storageLimit,
});
}
}, [activePlan, stats, error, statsError]);
}, [hasData, hasError, stats, activePlan]);
return {
error: error || statsError,