-
Notifications
You must be signed in to change notification settings - Fork 0
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
サインアウトモーダルの作成 #76
base: main
Are you sure you want to change the base?
サインアウトモーダルの作成 #76
Changes from all commits
90c99f4
960c66a
e3d1c33
60e8176
6c4f6be
e3c8fd8
2714fd3
ee7b469
81aad93
8da9284
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Generated by orval v6.30.2 🍺 | ||
* Do not edit manually. | ||
* Web開発研修6班 API | ||
* FY24卒Web開発研修6班のAPI仕様書です | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
|
||
export interface SchemaSignupRequest { | ||
password?: string; | ||
user_name?: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useEffect, useState } from 'react' | ||
import { Box, Button, Loading, Text, useDisclosure } from '@yamada-ui/react' | ||
import { useNavigate } from 'react-router-dom' | ||
import { usePostSignout, useGetUser } from '../../api/api' | ||
import { SignoutModal } from './SignoutModal' | ||
|
||
export const Header = () => { | ||
const navigate = useNavigate() | ||
const { data: user, isError, refetch, isFetching } = useGetUser() | ||
const [currentUser, setCurrentUser] = useState(user) | ||
const { isOpen, onOpen, onClose } = useDisclosure() | ||
|
||
const { mutate: signoutMutate } = usePostSignout({ | ||
mutation: { | ||
onSuccess: () => { | ||
setCurrentUser(undefined) | ||
navigate('/signin') | ||
} | ||
} | ||
}) | ||
|
||
useEffect(() => { | ||
if (isError) { | ||
setCurrentUser(undefined) | ||
} else { | ||
setCurrentUser(user) | ||
} | ||
}, [user, isError]) | ||
|
||
return ( | ||
<> | ||
<header className="app-header"> | ||
サンプルアプリケーション | ||
<Box display="flex" alignItems="center"> | ||
{isFetching ? ( | ||
<Loading variant="circles" size="6xl" color="cyan.500" /> | ||
) : isError || !currentUser ? ( | ||
<Button onClick={() => signoutMutate()}>サインイン</Button> | ||
) : ( | ||
<> | ||
<Text mr={2}>{currentUser.user_name}</Text> | ||
<Button onClick={onOpen}>サインアウト</Button> | ||
</> | ||
)} | ||
</Box> | ||
</header> | ||
<SignoutModal isOpen={isOpen} onClose={onClose} signoutMutate={signoutMutate} refetch={refetch} /> | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Button, Center, Divider, Modal, ModalBody, ModalFooter, ModalHeader } from '@yamada-ui/react' | ||
import { Link } from 'react-router-dom' | ||
|
||
interface props { | ||
isOpen: boolean | ||
onClose: () => void | ||
signoutMutate: () => void | ||
refetch: () => void | ||
} | ||
|
||
export const SignoutModal = ({ isOpen, onClose, signoutMutate, refetch }: props) => { | ||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<Center> | ||
<ModalHeader>警告</ModalHeader> | ||
</Center> | ||
<Divider variant="solid" my={2} /> | ||
<ModalBody>サインアウトを行います。よろしいですか?</ModalBody> | ||
<Divider variant="solid" my={2} /> | ||
<ModalFooter> | ||
<Button variant="ghost" onClick={onClose}> | ||
とじる | ||
</Button> | ||
<Link to="/"> | ||
<Button | ||
onClick={() => { | ||
signoutMutate() | ||
refetch() | ||
onClose() | ||
}} | ||
colorScheme="primary" | ||
> | ||
サインアウト | ||
</Button> | ||
</Link> | ||
</ModalFooter> | ||
</Modal> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Header } from './Header' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Headerをインポートするときに ./Header/Header ってなるのが嫌だったので。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,28 +71,24 @@ export const PostDetailRoute = () => { | |
<Button onClick={onOpen} colorScheme="primary"> | ||
削除 | ||
</Button> | ||
<> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここの<>が要らないので削除 |
||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<Center> | ||
<ModalHeader>警告</ModalHeader> | ||
</Center> | ||
<Divider variant="solid" /> | ||
<ModalBody>削除したら元に戻せません。削除しますか?</ModalBody> | ||
<Divider variant="solid" /> | ||
<ModalFooter> | ||
<Button variant="ghost" onClick={onClose}> | ||
とじる | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<Center> | ||
<ModalHeader>警告</ModalHeader> | ||
</Center> | ||
<Divider variant="solid" my={2} /> | ||
<ModalBody>削除したら元に戻せません。削除しますか?</ModalBody> | ||
<Divider variant="solid" my={2} /> | ||
<ModalFooter> | ||
<Button variant="ghost" onClick={onClose}> | ||
とじる | ||
</Button> | ||
<Link to="/"> | ||
<Button onClick={handleDelete} colorScheme="primary"> | ||
削除 | ||
</Button> | ||
<> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここも |
||
<Link to="/"> | ||
<Button onClick={handleDelete} colorScheme="primary"> | ||
削除 | ||
</Button> | ||
</Link> | ||
</> | ||
</ModalFooter> | ||
</Modal> | ||
</> | ||
</Link> | ||
</ModalFooter> | ||
</Modal> | ||
</> | ||
) : null} | ||
</HStack> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SignoutModalとして切り出し