Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Fix ] 그룹 생성 데이트피커 버튼 제출 오류 / 제출 완료 시 페이지 깜빡임 해결 #315

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/app/[user]/create-group/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@
import Modal from "@/common/component/Modal";
import Sidebar from "@/common/component/Sidebar";
import ToastProvider from "@/common/component/Toast";
import CodeClipboard from "@/shared/component/CodeClipboard";
import { sidebarWrapper } from "@/styles/shared.css";
import CreateGroupForm from "@/view/user/create-group/CreateGroupForm";

import { wrapper } from "@/view/user/create-group/index.css";
import { useRouter } from "next/navigation";
import { useState } from "react";

const CreateGroupPage = () => {
const router = useRouter();
const [responseCode, setResponseCode] = useState("");

const handleSuccess = (code: string) => {
setResponseCode(code);
};

return (
<main className={sidebarWrapper}>
<ToastProvider />
<Sidebar />
<Modal isOpen={true} onClose={() => router.back()} hasCloseBtn>
<div className={wrapper}>
<CreateGroupForm onSuccess={handleSuccess} />
{responseCode && <CodeClipboard code={responseCode} />}
<CreateGroupForm />
</div>
</Modal>
</main>
Expand Down
4 changes: 2 additions & 2 deletions src/app/join-group/[code]/query.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getGroupsByCode } from "@/app/api/groups";
import { joinGroupAction } from "@/app/join-group/[code]/action";
import { useMutation, useSuspenseQuery } from "@tanstack/react-query";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useRouter } from "next/navigation";

export const useGroupByCodeQuery = (code: string) => {
return useSuspenseQuery({
return useQuery({
queryKey: ["groupByCode", code],
queryFn: () => getGroupsByCode(code),
});
Expand Down
12 changes: 10 additions & 2 deletions src/common/component/Calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,21 @@ const renderCustomHeader = ({
}: CustomHeaderProps) => {
return (
<div className={customHeaderWrapperStyle}>
<button className={arrowWrapperStyle} onClick={decreaseMonth}>
<button
type="button"
className={arrowWrapperStyle}
onClick={decreaseMonth}
>
<IcnBtnArrowLeft className={leftArrowStyle({ rotate: false })} />
</button>
<div className={dateDetailStyle}>{`${date.getFullYear()}년 ${
date.getMonth() + 1
}월`}</div>
<button className={arrowWrapperStyle} onClick={increaseMonth}>
<button
type="button"
className={arrowWrapperStyle}
onClick={increaseMonth}
>
<IcnBtnArrowLeft className={leftArrowStyle({ rotate: true })} />
</button>
</div>
Expand Down
9 changes: 6 additions & 3 deletions src/shared/component/CodeClipboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ interface CodeClipboardProps {
}

const CodeClipboard = ({ label, code }: CodeClipboardProps) => {
const { data: groupInfo } = useGroupByCodeQuery(code);
const { data: groupInfo, isSuccess } = useGroupByCodeQuery(code);

const { isCopied, copy } = useClipboard(
groupInfo?.ownerNickname,
groupInfo?.name,
groupInfo?.ownerNickname ?? "",
groupInfo?.name ?? "",
);

if (!isSuccess) return null;

return (
<div className={wrapperStyle}>
{label && <p className={labelStyle}>{label}</p>}
Expand Down
12 changes: 7 additions & 5 deletions src/view/user/create-group/CreateGroupForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IcnPlus } from "@/asset/svg";
import Button from "@/common/component/Button";
import SupportingText from "@/common/component/SupportingText";
import { useToast } from "@/common/hook/useToast";
import CodeClipboard from "@/shared/component/CodeClipboard";
import { Form } from "@/shared/component/Form";
import DateFormController from "@/shared/component/GroupInfoForm/DateFormController";
import DescFormController from "@/shared/component/GroupInfoForm/DescFormController";
Expand All @@ -16,15 +17,15 @@ import {
} from "@/shared/component/GroupInfoForm/index.css";
import { getGroupFormData } from "@/shared/component/GroupInfoForm/util";
import { zodResolver } from "@hookform/resolvers/zod";
import { useState } from "react";
import { useForm } from "react-hook-form";
import type { z } from "zod";
import { submitBtnStyle } from "./index.css";

type CreateGroupFormProps = {
onSuccess: (code: string) => void;
};
const CreateGroupForm = ({ onSuccess }: CreateGroupFormProps) => {
const CreateGroupForm = () => {
const { showToast } = useToast();
const [code, setCode] = useState("");

const form = useForm<z.infer<typeof groupSchema>>({
resolver: zodResolver(groupSchema),
mode: "onTouched",
Expand All @@ -41,7 +42,7 @@ const CreateGroupForm = ({ onSuccess }: CreateGroupFormProps) => {
const data = getGroupFormData(values);
const code = await createGroupAction(data);

onSuccess(code);
setCode(code);
showToast("스터디가 정상적으로 만들어졌어요.", "success");
};
const error = form.formState.errors.endDate;
Expand Down Expand Up @@ -86,6 +87,7 @@ const CreateGroupForm = ({ onSuccess }: CreateGroupFormProps) => {
스터디 만들기
</Button>
</form>
{code && <CodeClipboard code={code} />}
</Form>
);
};
Expand Down
Loading