Skip to content

Commit

Permalink
Merge pull request #81 from jphacks/feat/phone-number
Browse files Browse the repository at this point in the history
電話番号を設定できるようにした
  • Loading branch information
yuto-trd authored Oct 27, 2024
2 parents 92e761b + bf2eea6 commit c89291c
Showing 1 changed file with 32 additions and 4 deletions.
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

0 comments on commit c89291c

Please sign in to comment.