97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
'use client'
|
|
|
|
// apps/web/src/components/meetings/memo-form.tsx
|
|
// 회의 메모 작성 — meeting_memos INSERT + Realtime 구독 유도
|
|
|
|
import { useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import { Box, TextField, Button, Stack, Alert } from '@mui/material'
|
|
import NoteAddIcon from '@mui/icons-material/NoteAdd'
|
|
import { d3roPalette } from '@d3ro/ui/theme'
|
|
import { getSupabaseBrowserClient } from '@/lib/supabase-browser'
|
|
|
|
interface MemoFormProps {
|
|
meetingId: string
|
|
meetingStartedAt: string
|
|
}
|
|
|
|
export function MemoForm({ meetingId, meetingStartedAt }: MemoFormProps): React.ReactElement {
|
|
const router = useRouter()
|
|
const [content, setContent] = useState('')
|
|
const [busy, setBusy] = useState(false)
|
|
const [error, setError] = useState<string | null>(null)
|
|
|
|
async function handleSubmit(): Promise<void> {
|
|
if (!content.trim()) return
|
|
setError(null)
|
|
setBusy(true)
|
|
try {
|
|
const supabase = getSupabaseBrowserClient()
|
|
const {
|
|
data: { user }
|
|
} = await supabase.auth.getUser()
|
|
if (!user) {
|
|
setError('로그인이 필요합니다')
|
|
return
|
|
}
|
|
|
|
// 회의 시작 시간 대비 경과 밀리초
|
|
const elapsedMs = Math.max(0, Date.now() - new Date(meetingStartedAt).getTime())
|
|
|
|
const { error: insertErr } = await supabase.from('meeting_memos').insert({
|
|
meeting_id: meetingId,
|
|
user_id: user.id,
|
|
content: content.trim(),
|
|
timestamp_ms: elapsedMs
|
|
})
|
|
|
|
if (insertErr) {
|
|
setError(insertErr.message)
|
|
return
|
|
}
|
|
|
|
setContent('')
|
|
router.refresh()
|
|
} finally {
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Box sx={{ mt: 2 }}>
|
|
<Stack direction="row" spacing={1}>
|
|
<TextField
|
|
fullWidth
|
|
size="small"
|
|
value={content}
|
|
onChange={(e) => setContent(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter' && !e.shiftKey) {
|
|
e.preventDefault()
|
|
void handleSubmit()
|
|
}
|
|
}}
|
|
placeholder="메모 입력... (Enter 저장)"
|
|
disabled={busy}
|
|
/>
|
|
<Button
|
|
variant="outlined"
|
|
size="small"
|
|
startIcon={<NoteAddIcon />}
|
|
onClick={() => void handleSubmit()}
|
|
disabled={busy || !content.trim()}
|
|
>
|
|
저장
|
|
</Button>
|
|
</Stack>
|
|
{error && (
|
|
<Alert severity="error" variant="outlined" sx={{ mt: 1, fontSize: 11 }}>
|
|
{error}
|
|
</Alert>
|
|
)}
|
|
<Box sx={{ color: d3roPalette.text.muted, fontSize: 11, mt: 0.5 }}>
|
|
회의 시작 후 경과 시간으로 timestamp_ms가 자동 계산됩니다.
|
|
</Box>
|
|
</Box>
|
|
)
|
|
}
|