Skip to content

Commit

Permalink
fix: 후원하기 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ej070961 committed Aug 10, 2024
1 parent 7df67c9 commit 67424ac
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 62 deletions.
18 changes: 10 additions & 8 deletions src/components/SponsorDetail/DonateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function DonateModal({ onClose }: { onClose: () => void }) {
formState: { isValid },
} = useForm<FormValue>({
mode: "onChange",
defaultValues: {
bank: "001",
},
});
const accessToken = useAuthStore((state) => state.accessToken);
const { nickname } = useAuthStore.getState().userData;
Expand All @@ -53,7 +56,7 @@ function DonateModal({ onClose }: { onClose: () => void }) {
const navigate = useNavigate();
const onSubmitHandler: SubmitHandler<FormValue> = async () => {
const { amount, bank, account } = getValues();

console.log(amount, bank, account);
if (!bank || !account) {
alert("은행명 정보와 계좌번호를 입력해 주세요.");
return; // 요청 보내지 않음
Expand All @@ -67,10 +70,13 @@ function DonateModal({ onClose }: { onClose: () => void }) {
account
);

if (res.status === 200) {
if (res.success) {
setIsFinished(true);
console.log(isFinished);
}
};
console.log(isFinished);

if (!isLoading && !isProgressLoading && data && ProgressData) {
return (
<Overlay onClick={onClose}>
Expand Down Expand Up @@ -103,12 +109,8 @@ function DonateModal({ onClose }: { onClose: () => void }) {
<AccountForm
bankValue={watch("bank")}
accountValue={watch("account")}
onBankChange={(value) =>
setValue("bank", value, { shouldValidate: true })
}
onAccountChange={(value) =>
setValue("account", value, { shouldValidate: true })
}
onBankChange={(value) => setValue("bank", value)}
onAccountChange={(value) => setValue("account", value)}
/>
<Button type="submit" disabled={!isValid}>
후원하기
Expand Down
19 changes: 9 additions & 10 deletions src/components/SponsorDetail/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ function Header({ memberId, nickname }: HeaderProps) {
// });
const navigate = useNavigate();
const { supportId } = useParams<{ supportId: string }>();
const accessToken = useAuthStore((state) => state.accessToken!);
console.log(isOpenDonate);
const accessToken = useAuthStore((state) => state.accessToken);
// 수정하기 클릭시 함수 호출
const handleUpdate = async () => {
const res = await getUpdate(supportId!, accessToken);
if (res.success) {
navigate("/sponsor-register", {
state: { data: res.data, mode: "update" },
});
}
};
// const handleUpdate = async () => {
// const res = await getUpdate(supportId!, accessToken);
// if (res.success) {
// navigate("/sponsor-register", {
// state: { data: res.data, mode: "update" },
// });
// }
// };
return (
<>
<Container>
Expand Down
88 changes: 44 additions & 44 deletions src/storage/useAuthStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,57 @@ import create from "zustand";
import { persist } from "zustand/middleware";

export type UserData = {
id?: number;
nickname?: string;
email?: string;
profile?: string;
role?: string;
registerType?: string;
id?: number;
nickname?: string;
email?: string;
profile?: string;
role?: string;
registerType?: string;
};

type AuthStore = {
isLoggedIn: boolean;
login: () => void;
logout: () => void;
userData: UserData;
setUserData: (userData: Partial<UserData>) => void;
setUserDataValue: (key: keyof UserData, value: any) => void;
accessToken?: string;
setAccessToken: (accessToken: string) => void;
refreshToken?: string;
setRefreshToken: (refreshToken: string) => void;
isLoggedIn: boolean;
login: () => void;
logout: () => void;
userData: UserData;
setUserData: (userData: Partial<UserData>) => void;
setUserDataValue: (key: keyof UserData, value: any) => void;
accessToken?: string;
setAccessToken: (accessToken: string) => void;
refreshToken?: string;
setRefreshToken: (refreshToken: string) => void;
};

const useAuthStore = create(
persist<AuthStore>(
(set) => ({
isLoggedIn: false,
login: () => set({ isLoggedIn: true }),
logout: () =>
set({
isLoggedIn: false,
userData: {},
accessToken: "",
refreshToken: "",
}),
userData: {},
setUserData: (userData) => set({ userData }),
setUserDataValue: (key, value) =>
set((state) => ({
userData: {
...state.userData,
[key]: value,
},
})),
accessToken: "",
setAccessToken: (accessToken) => set({ accessToken }),
refreshToken: "",
setRefreshToken: (refreshToken) => set({ refreshToken }),
persist<AuthStore>(
(set) => ({
isLoggedIn: false,
login: () => set({ isLoggedIn: true }),
logout: () =>
set({
isLoggedIn: false,
userData: {},
accessToken: "",
refreshToken: "",
}),
{
name: "userInfoStorage",
}
)
userData: {},
setUserData: (userData) => set({ userData }),
setUserDataValue: (key, value) =>
set((state) => ({
userData: {
...state.userData,
[key]: value,
},
})),
accessToken: "",
setAccessToken: (accessToken) => set({ accessToken }),
refreshToken: "",
setRefreshToken: (refreshToken) => set({ refreshToken }),
}),
{
name: "userInfoStorage",
}
)
);

export default useAuthStore;

0 comments on commit 67424ac

Please sign in to comment.