Skip to content

Commit

Permalink
fix: 버그 수정5
Browse files Browse the repository at this point in the history
  • Loading branch information
abcxj123 committed Jun 10, 2024
1 parent f315bc7 commit f469318
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/pages/consume/ConsumeEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CategoryEditItem } from '../../components/molecules/CategoryEditItem';
import { Button } from '../../components/ui/Button';
import { useNavigate } from 'react-router-dom';
import { BudgetReqType } from '../../types/budget';
import { useMutation, useQuery } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { ApiClient } from '../../apis/apiClient';

type BudgetEditType = {
Expand All @@ -31,6 +31,7 @@ const CategoryConvert = {

export const ConsumeEdit = () => {
const navigate = useNavigate();
const queryClient = useQueryClient();

const { data: spendData, isSuccess: successSpend } = useQuery({
queryKey: ['spend3'],
Expand Down
37 changes: 26 additions & 11 deletions src/pages/consume/ConsumePattern.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RiPencilFill } from 'react-icons/ri';
import { useNavigate } from 'react-router-dom';
import { CategoryItem } from '../../components/molecules/CategoryItem';
import { CategorySpendCard } from '../../components/organisms/CategorySpendCard';
import { useQuery } from '@tanstack/react-query';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { ApiClient } from '../../apis/apiClient';
import { SpendType } from '../../types/spend';

Expand All @@ -24,12 +24,14 @@ const Category = {

export const ConsumePattern = () => {
const navigate = useNavigate();
const queryClient = useQueryClient();

const [year, setYear] = useState<number>(dateYear);
const [month, setMonth] = useState<number>(dateMonth);
const [spend, setSpend] = useState<number>(0);
const [budget, setBudget] = useState<number>(0);
const [percent, setPercent] = useState<number>(0);
const [patch, setPatch] = useState<boolean>(false);

const spendQuery = useQuery({
queryKey: ['category', year, month],
Expand All @@ -40,8 +42,8 @@ export const ConsumePattern = () => {
staleTime: 100,
});

const { data: budgetData, isSuccess: successBudget } = useQuery({
queryKey: ['budget'],
const budgetQuery = useQuery({
queryKey: ['budget', patch],
queryFn: () => {
const res = ApiClient.getInstance().getTotalBudget();
return res;
Expand All @@ -67,25 +69,36 @@ export const ConsumePattern = () => {
}, [spendQuery.data]);

useEffect(() => {
if (spendQuery.isSuccess && successBudget) {
if (spendQuery.isSuccess && budgetQuery) {
try {
ApiClient.getInstance()
.getSpendList(dateYear, dateMonth)
.then((res) => {
setSpend(res.sum);
setPercent(Math.round((res.sum / budget) * 100));
console.log();
});
} catch (e) {
console.log(e);
}
}
}, [spendQuery.isSuccess, successBudget]);
}, [spendQuery, budgetQuery]);

useEffect(() => {
if (successBudget) {
setBudget(budgetData.sum);
if (budgetQuery.isSuccess) {
setBudget(budgetQuery.data.sum);
}
}, [successBudget]);
}, [budgetQuery.isSuccess]);

useEffect(() => {
if (budgetQuery.data) {
console.log(budgetQuery.data.sum);
}
}, [budgetQuery.data]);

useEffect(() => {
queryClient.invalidateQueries({ queryKey: ['budget'] });
}, []);

const onClickButton = () => {
navigate('/consumeEdit');
Expand Down Expand Up @@ -118,7 +131,7 @@ export const ConsumePattern = () => {
<p className='flex items-center font-hanaBold text-3xl'>예산</p>
<div className='flex flex-row gap-3 items-center'>
<p className='font-hanaMedium text-3xl'>
{budget.toLocaleString()}
{budgetQuery.data?.sum.toLocaleString()}
</p>
<RiPencilFill
size={20}
Expand All @@ -131,10 +144,12 @@ export const ConsumePattern = () => {
{/* 프로그래스바 */}
<div className='flex flex-row h-8 w-full my-6'>
<div
className={`bg-hanaGreen w-[${percent}%] h-full rounded-l-lg`}
className={`bg-hanaGreen h-full rounded-l-lg`}
style={{ width: `${percent}%` }}
></div>
<div
className={`bg-gray-200 w-[${100 - percent}%] h-full rounded-r-lg border-2 flex items-center`}
className={`bg-gray-200 h-full rounded-r-lg border-2 flex items-center`}
style={{ width: `${100 - percent}%` }}
>
<p className='ml-1 font-hanaMedium text-xl'>{percent}%</p>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/pages/main/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { FaChevronRight } from 'react-icons/fa';
import { AccountSummaryItem } from '../../components/molecules/AccountSummaryItem';
import { getCookie, removeCookie } from '../../utils/cookie';
import { AccountType } from '../../types/account';
import { useQuery } from '@tanstack/react-query';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { ApiClient } from '../../apis/apiClient';
import { useNavigate } from 'react-router-dom';
import { useEffect } from 'react';

export const MyPage = () => {
const navigate = useNavigate();
const queryClient = useQueryClient();
const name = getCookie('name');

const logout = () => {
Expand Down Expand Up @@ -38,6 +40,10 @@ export const MyPage = () => {
},
});

useEffect(() => {
queryClient.invalidateQueries({ queryKey: ['accounts'] });
}, []);

return (
<>
<div className='pt-20 w-11/12 flex items-center m-auto mb-12'>
Expand Down
4 changes: 2 additions & 2 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ export default {
},
minHeight: {
'real-screen': 'calc(100vh - 100px)',
'real-screen2': 'calc(100vh - 82.5px)',
'real-screen3': 'calc(100vh - 182.5px)',
'real-screen2': 'calc(100vh - 50px)',
'real-screen3': 'calc(100vh - 150px)',
},
backgroundImage: {
roadmap4: "url('/images/roadmap.svg')",
Expand Down

0 comments on commit f469318

Please sign in to comment.