-
Notifications
You must be signed in to change notification settings - Fork 0
feat(frontend): 그룹 기획 페이지 구현 #21
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
Open
song-eun
wants to merge
10
commits into
main
Choose a base branch
from
feat/group-planning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+534
−2
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2f00976
style(frontend): StepCard 컴포넌트 w-full 추가
song-eun 1b62148
style(frontend): Header 컴포넌트 shrink-0 추가
song-eun afd7e0a
feat(frontend): 그룹 기획 다국어 번역 추가
song-eun d009fdc
feat(frontend): 엠블럼 생성 (Step2) 컴포넌트 구현
song-eun 695b1db
feat(frontend): GroupPlanningForm 컴포넌트 구현
song-eun ce00dd7
feat(frontend): group 페이지 구현
song-eun 507c2c8
feat(frontend): 그룹 기획 스토리북 추가
song-eun cb84079
style(frontend): 이미지 로딩 전 배경 색상 수정
song-eun f1bef46
fix(frontend): 불필요한 연산 삭제
song-eun 50dc33c
fix(frontend): storybook alert를 action으로 변경
song-eun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| "use client"; | ||
|
|
||
| import { useRouter } from "next/navigation"; | ||
| import { useEffect, useMemo, useState } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
|
|
||
| import { useToast } from "@/app/providers/Toast"; | ||
| import { GroupPlanningForm } from "@/components/group-creation"; | ||
| import { Header } from "@/components/Header"; | ||
| import { Loading } from "@/components/Loading"; | ||
| import { AIdolRepository } from "@/repositories/AIdolRepository"; | ||
| import type { AIdol } from "@/schemas"; | ||
| import { getApiService } from "@/services/ApiService"; | ||
|
|
||
| interface GroupPageProps { | ||
| params: { lang: string; aidolId: string }; | ||
| } | ||
|
|
||
| export default function GroupPage({ params }: GroupPageProps) { | ||
| const { t } = useTranslation(); | ||
| const router = useRouter(); | ||
| const { showToast } = useToast(); | ||
| const { lang, aidolId } = params; | ||
|
|
||
| const [aidol, setAidol] = useState<AIdol | null>(null); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
| const [isGeneratingImage, setIsGeneratingImage] = useState(false); | ||
|
|
||
| const aidolRepository = useMemo( | ||
| () => new AIdolRepository(getApiService()), | ||
| [], | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| const fetchAidol = async () => { | ||
| setIsLoading(true); | ||
| try { | ||
| const response = await aidolRepository.getOne({ id: aidolId }); | ||
| setAidol(response.data); | ||
| } catch (error) { | ||
| console.error("Failed to fetch aidol:", error); | ||
| showToast(t("aidol:groupPlanning.error.load"), "error"); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| void fetchAidol(); | ||
| }, [aidolId, aidolRepository, showToast, t]); | ||
|
|
||
| const handleGenerateImage = async ( | ||
| prompt: string, | ||
| ): Promise<string | null> => { | ||
| setIsGeneratingImage(true); | ||
| try { | ||
| const response = await aidolRepository.generateImage({ prompt }); | ||
| return response.data.imageUrl; | ||
| } catch (error) { | ||
| console.error("Failed to generate image:", error); | ||
| showToast(t("aidol:groupPlanning.error.generate"), "error"); | ||
| return null; | ||
| } finally { | ||
| setIsGeneratingImage(false); | ||
| } | ||
| }; | ||
|
|
||
| const handleSubmit = async (data: { name: string; emblemUrl: string }) => { | ||
| setIsSubmitting(true); | ||
| try { | ||
| await aidolRepository.update({ | ||
| id: aidolId, | ||
| variables: { | ||
| name: data.name, | ||
| profileImageUrl: data.emblemUrl, | ||
| }, | ||
| }); | ||
| router.push(`/${lang}/${aidolId}/complete`); | ||
| } catch (error) { | ||
| console.error("Failed to update aidol:", error); | ||
| showToast(t("aidol:groupPlanning.error.update"), "error"); | ||
| } finally { | ||
| setIsSubmitting(false); | ||
| } | ||
| }; | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <div className="bg-base-100 flex h-screen flex-col"> | ||
| <Header title={t("aidol:groupPlanning.header")} /> | ||
| <Loading /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="bg-base-100 flex h-screen flex-col"> | ||
| <Header title={t("aidol:groupPlanning.header")} /> | ||
| <GroupPlanningForm | ||
| initialName={aidol?.name} | ||
| initialEmblemUrl={aidol?.profileImageUrl} | ||
| onSubmit={handleSubmit} | ||
| onGenerateImage={handleGenerateImage} | ||
| isLoading={isSubmitting} | ||
| isGeneratingImage={isGeneratingImage} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { SparklesIcon } from "@heroicons/react/24/outline"; | ||
| import clsx from "clsx"; | ||
| import { useState } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
|
|
||
| import { ImagePreview } from "@/components/companion/ImagePreview"; | ||
| import { StepCard } from "@/components/creation/StepCard"; | ||
|
|
||
| interface EmblemStepProps { | ||
| emblemUrl: string; | ||
| isGeneratingImage: boolean; | ||
| onGenerate: (prompt: string) => void; | ||
| } | ||
|
|
||
| export function EmblemStep({ | ||
| emblemUrl, | ||
| isGeneratingImage, | ||
| onGenerate, | ||
| }: EmblemStepProps) { | ||
| const { t } = useTranslation(); | ||
| const [prompt, setPrompt] = useState(""); | ||
|
|
||
| const handleGenerate = () => { | ||
| if (prompt.trim()) { | ||
| onGenerate(prompt.trim()); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <StepCard step={2} title={t("aidol:groupPlanning.step2Title")}> | ||
| <input | ||
| type="text" | ||
| value={prompt} | ||
| onChange={(e) => setPrompt(e.target.value)} | ||
| placeholder={t("aidol:groupPlanning.promptPlaceholder")} | ||
| className="border-base-300 text-body-m placeholder:text-base-300 w-full rounded-lg border bg-white px-4 py-3 text-black focus:outline-none" | ||
| maxLength={200} | ||
| disabled={isGeneratingImage} | ||
| /> | ||
| <button | ||
| type="button" | ||
| onClick={handleGenerate} | ||
| disabled={!prompt.trim() || isGeneratingImage} | ||
| className={clsx( | ||
| "btn btn-lg text-label-l w-full rounded-lg border-0 py-4 text-white shadow-none", | ||
| prompt.trim() && !isGeneratingImage ? "bg-primary" : "bg-primary/20", | ||
| )} | ||
| > | ||
| {emblemUrl | ||
| ? t("aidol:groupPlanning.regenerate") | ||
| : t("aidol:groupPlanning.generate")} | ||
| </button> | ||
| <div className="border-base-300 bg-base-100 flex h-72 items-center justify-center overflow-hidden rounded-lg border"> | ||
| {isGeneratingImage ? ( | ||
| <span className="loading loading-spinner loading-lg text-primary" /> | ||
| ) : emblemUrl ? ( | ||
| <ImagePreview url={emblemUrl} alt="emblem" /> | ||
| ) : ( | ||
| <div className="text-neutral flex flex-col items-center gap-4"> | ||
| <SparklesIcon className="size-6" /> | ||
| <p className="text-body-m text-center whitespace-pre-line"> | ||
| {t("aidol:groupPlanning.emptyImage")} | ||
| </p> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </StepCard> | ||
| ); | ||
| } | ||
107 changes: 107 additions & 0 deletions
107
frontend/src/components/group-creation/GroupPlanningForm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import clsx from "clsx"; | ||
| import { useState } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
|
|
||
| import { StepCard } from "@/components/creation/StepCard"; | ||
|
|
||
| import { EmblemStep } from "./EmblemStep"; | ||
|
|
||
| interface GroupPlanningFormProps { | ||
| initialStep?: 1 | 2; | ||
| initialName?: string; | ||
| initialEmblemUrl?: string; | ||
| onSubmit: (data: { name: string; emblemUrl: string }) => void; | ||
| onGenerateImage: (prompt: string) => Promise<string | null>; | ||
| isLoading: boolean; | ||
| isGeneratingImage: boolean; | ||
| } | ||
|
|
||
| export function GroupPlanningForm({ | ||
| initialStep = 1, | ||
| initialName = "", | ||
| initialEmblemUrl = "", | ||
| onSubmit, | ||
| onGenerateImage, | ||
| isLoading, | ||
| isGeneratingImage, | ||
| }: GroupPlanningFormProps) { | ||
| const { t } = useTranslation(); | ||
| const [step, setStep] = useState(initialStep); | ||
| const [name, setName] = useState(initialName); | ||
| const [emblemUrl, setEmblemUrl] = useState(initialEmblemUrl); | ||
|
|
||
| const canProceedStep1 = name.trim().length > 0; | ||
| const canProceedStep2 = emblemUrl.length > 0; | ||
|
|
||
| const handleNext = () => { | ||
| if (step === 1 && canProceedStep1) { | ||
| setStep(2); | ||
| } else if (step === 2 && canProceedStep2) { | ||
| onSubmit({ name: name.trim(), emblemUrl }); | ||
| } | ||
| }; | ||
|
|
||
| const handleGenerateImage = async (prompt: string) => { | ||
| const url = await onGenerateImage(prompt); | ||
| if (url) { | ||
| setEmblemUrl(url); | ||
| } | ||
| }; | ||
|
|
||
| const canProceed = step === 1 ? canProceedStep1 : canProceedStep2; | ||
|
|
||
| return ( | ||
| <div className="flex flex-1 flex-col gap-6"> | ||
| <div className="px-6 py-4"> | ||
| <progress | ||
| className="progress progress-primary h-3 w-full" | ||
| value={step} | ||
| max={2} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="flex w-full flex-1 flex-col items-center gap-6 overflow-y-auto px-6 pb-24"> | ||
| {step === 1 && ( | ||
| <StepCard step={1} title={t("aidol:groupPlanning.step1Title")}> | ||
| <input | ||
| type="text" | ||
| value={name} | ||
| onChange={(e) => setName(e.target.value)} | ||
| placeholder={t("aidol:groupPlanning.namePlaceholder")} | ||
| className="border-base-300 text-body-m placeholder:text-base-300 w-full rounded-lg border bg-white px-4 py-3 text-black focus:outline-none" | ||
song-eun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| maxLength={20} | ||
| /> | ||
| </StepCard> | ||
| )} | ||
|
|
||
| {step === 2 && ( | ||
| <EmblemStep | ||
| emblemUrl={emblemUrl} | ||
| isGeneratingImage={isGeneratingImage} | ||
| onGenerate={(prompt) => void handleGenerateImage(prompt)} | ||
| /> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="max-w-mobile fixed inset-x-0 bottom-0 z-10 mx-auto px-6 pb-6"> | ||
| <div className="bg-base-100"> | ||
| <button | ||
| type="button" | ||
| onClick={handleNext} | ||
| disabled={!canProceed || isLoading} | ||
| className={clsx( | ||
| "btn btn-lg text-label-l text-neutral-content w-full rounded-lg border-0 shadow-none", | ||
| canProceed && !isLoading ? "bg-neutral" : "bg-neutral/20", | ||
| )} | ||
| > | ||
| {isLoading ? ( | ||
| <span className="loading loading-spinner loading-sm" /> | ||
| ) : ( | ||
| t("aidol:groupPlanning.next") | ||
| )} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { EmblemStep } from "./EmblemStep"; | ||
| export { GroupPlanningForm } from "./GroupPlanningForm"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.