Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
fix: Fix submit logic and fetch data
Browse files Browse the repository at this point in the history
  • Loading branch information
Sansai-snct committed Dec 16, 2022
1 parent d2068ef commit d44d687
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/pages/edit/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ import Image from "next/image";
import { onAuthStateChanged } from "firebase/auth";
import type { User } from "firebase/auth";
import { auth } from "../../libs/firebase/init";
import { getCardList, createCardListItem } from "../../libs/firebase/store";
import {
getCardList,
createCardListItem,
getInfo,
} from "../../libs/firebase/store";
import type {
StoreCardList,
CreateStoreCardListItem,
ListInfo,
} from "../../libs/firebase/types";
import { EditCard } from "../../components/card/edit";
import { createGetLayout } from "../../components/layout/edit";
Expand All @@ -36,8 +41,7 @@ const Edit: NextPageWithLayout = () => {
const [file, setFile] = useState<File>();
const listid = id;

// TODO: fetchData
const title = "Title";
const [title, setTitle] = useState("");

const { register, handleSubmit, reset } = useForm<CreateStoreCardListItem>();

Expand All @@ -53,12 +57,7 @@ const Edit: NextPageWithLayout = () => {
};

const onSubmit: SubmitHandler<CreateStoreCardListItem> = async (result) => {
if (
!user ||
!(typeof id === "string") ||
!file ||
!inputRef.current?.value
) {
if (!user || !(typeof id === "string")) {
return;
}
const data: CreateStoreCardListItem = {
Expand All @@ -75,6 +74,8 @@ const Edit: NextPageWithLayout = () => {
const authStateChanged = onAuthStateChanged(auth, async (u) => {
if (u && typeof listid === "string") {
const res = await getCardList(u.uid, listid);
const info: ListInfo = await getInfo(u.uid, listid);
if (typeof info !== "undefined") setTitle(info.title);
setList(res);
setUser(u);
}
Expand Down

0 comments on commit d44d687

Please sign in to comment.