Files
btrc-hub/frontend/src/components/users/UserCodeDialogue.tsx
T
みてるぞ eb975e5301 プリフェッチ実装(#140) (#256)
Merge branch 'main' into feature/140

#140

Merge remote-tracking branch 'origin/main' into feature/140

#140

#140

#140

#140

#140

Merge remote-tracking branch 'origin/main' into feature/140

#140

#140

#140

#140

#140

#140

#140

#140

#140

#140

#140

Merge remote-tracking branch 'origin/main' into feature/140

Merge remote-tracking branch 'origin/main' into feature/140

#140 ぼちぼち

Merge remote-tracking branch 'origin/main' into feature/140

#140

#140

#140

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #256
2026-02-11 13:27:28 +09:00

54 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Button } from '@/components/ui/button'
import { Dialog,
DialogContent,
DialogTitle } from '@/components/ui/dialog'
import { toast } from '@/components/ui/use-toast'
import { apiPost } from '@/lib/api'
import type { User } from '@/types'
type Props = { visible: boolean
onVisibleChange: (visible: boolean) => void
user: User | null
setUser: React.Dispatch<React.SetStateAction<User | null>> }
export default ({ visible, onVisibleChange, user, setUser }: Props) => {
const handleChange = async () => {
if (!(user))
return
if (!(confirm ('引継ぎコードを再発行しますか?\n再発行するとほかのブラウザからはログアウトされます.')))
return
const data = await apiPost<{ code: string }> ('/users/code/renew', { },
{ headers: { 'Content-Type': 'multipart/form-data' } })
if (data.code)
{
localStorage.setItem ('user_code', data.code)
setUser (user => ({ ...user, inheritanceCode: data.code } as User))
toast ({ title: '再発行しました.' })
}
}
return (
<Dialog open={visible} onOpenChange={onVisibleChange}>
<DialogContent>
<DialogTitle></DialogTitle>
<div>
<p></p>
<div className="m-2">{user?.inheritanceCode}</div>
<p className="mt-1 text-sm text-red-500">
!
</p>
<div className="my-4">
<Button onClick={handleChange}
className="px-4 py-2 bg-red-600 text-white rounded disabled:bg-gray-400">
</Button>
</div>
</div>
</DialogContent>
</Dialog>)
}