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

電話番号を設定できるようにした #81

Merged
merged 3 commits into from
Oct 27, 2024
Merged
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
36 changes: 32 additions & 4 deletions task_yell/src/app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { signOut } from "@/firebase/auth";
import { auth } from "@/firebase/client-app";
import { auth, db } from "@/firebase/client-app";
import { createEvent, readEvents } from "@/lib/events";
import { Category, Priority } from "@/lib/types";
import {
Expand Down Expand Up @@ -57,6 +57,12 @@ import {
subMonths,
} from "date-fns";
import { ja } from "date-fns/locale";
import {
doc,
getDoc,
setDoc,
updateDoc,
} from "firebase/firestore";
import { AnimatePresence, motion, useDragControls } from "framer-motion";
import {
ChevronLeft,
Expand Down Expand Up @@ -756,10 +762,31 @@ export default function Home() {
{item.label}
</Button>
{item.label === "通知" && isNotificationsOpen && (
<div className="ml-7 mt-2 space-y-4">
<form
className="ml-7 mt-2 space-y-4"
action={async (data) => {
if (auth.currentUser) {
const docRef = doc(db, "users", auth.currentUser.uid);
const snapshot = await getDoc(docRef);
if (snapshot.exists()) {
await updateDoc(docRef, {
phoneNumber: data.get("phoneNumber"),
});
} else {
setDoc(docRef, {
phoneNumber: data.get("phoneNumber"),
});
}
}
}}
>
<div className="space-y-2">
<Label htmlFor="phone">電話番号</Label>
<Input id="phone" placeholder="電話番号を入力" />
<Input
id="phone"
name="phoneNumber"
placeholder="+8190XXXXYYYY"
/>
</div>
<div className="flex items-center space-x-2">
<Switch
Expand All @@ -769,7 +796,8 @@ export default function Home() {
/>
<Label htmlFor="notifications">通知を有効にする</Label>
</div>
</div>
<Button type="submit">保存</Button>
</form>
)}
</li>
))}
Expand Down
Loading