-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
167 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,10 @@ | ||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" DATETIME NOT NULL, | ||
"displayName" TEXT NOT NULL | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_displayName_key" ON "User"("displayName"); |
This file contains 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 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 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 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,54 @@ | ||
import { Box, Button, FormControl, FormLabel, Input } from '@chakra-ui/react'; | ||
import type { NextPage } from 'next'; | ||
import { revalidatePath } from 'next/cache'; | ||
import { z } from 'zod'; | ||
import { zfd } from 'zod-form-data'; | ||
|
||
import { prisma } from '../../../infrastructures/prisma'; | ||
import { getNonNullableSessionOnServer } from '../../../utils/session'; | ||
|
||
const SettingsPage: NextPage = async () => { | ||
const session = await getNonNullableSessionOnServer(); | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
id: session.getUserId(), | ||
}, | ||
}); | ||
|
||
return ( | ||
<Box> | ||
<form action={updateDisplayName}> | ||
<FormControl> | ||
<FormLabel>あなたの表示名</FormLabel> | ||
<Input defaultValue={user?.displayName} name="displayName" type="text" /> | ||
</FormControl> | ||
<Button colorScheme="blue" mt={4} type="submit"> | ||
更新 | ||
</Button> | ||
</form> | ||
</Box> | ||
); | ||
}; | ||
|
||
const inputSchema = zfd.formData({ | ||
displayName: z.string().min(1), | ||
}); | ||
|
||
async function updateDisplayName(formData: FormData): Promise<void> { | ||
'use server'; | ||
const input = inputSchema.parse(formData); | ||
const session = await getNonNullableSessionOnServer(); | ||
await prisma.user.update({ | ||
where: { | ||
id: session.getUserId(), | ||
}, | ||
data: { | ||
displayName: input.displayName, | ||
}, | ||
}); | ||
|
||
// ユーザ名の変更を全ページに反映する。 | ||
revalidatePath('/', 'layout'); | ||
} | ||
|
||
export default SettingsPage; |
This file contains 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 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 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 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 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,21 @@ | ||
'use client'; | ||
import { MenuItem } from '@chakra-ui/react'; | ||
import { useRouter } from 'next/navigation'; | ||
import React from 'react'; | ||
import { FaSignOutAlt } from 'react-icons/fa'; | ||
import { signOut } from 'supertokens-auth-react/recipe/session'; | ||
|
||
export const SignOutMenuItem: React.FC = () => { | ||
const router = useRouter(); | ||
return ( | ||
<MenuItem | ||
icon={<FaSignOutAlt size="1.5em" />} | ||
onClick={async () => { | ||
await signOut(); | ||
router.push('/'); | ||
}} | ||
> | ||
サインアウト | ||
</MenuItem> | ||
); | ||
}; |
Oops, something went wrong.