Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/app/api/contact/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { NextResponse } from 'next/server'
import { Resend } from 'resend'
import { createCorsResponse, createCorsOptionsResponse } from '@/lib/api/cors'

// 環境変数から取得(.env.localのAPPS_SCRIPT_URLと一致させる)
const scriptUrl = process.env.APPS_SCRIPT_URL
const RESEND_FROM = process.env.RESEND_FROM ?? 'onboarding@resend.dev'

interface ContactPayload {
name: string
Expand All @@ -20,6 +22,15 @@ interface GoogleScriptResponse {
error?: string
}

function escapeHtml(s: string): string {
return s
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
}

export async function POST(request: Request) {
// デバッグ用ログ
console.log('=== Contact API Debug ===')
Expand Down Expand Up @@ -100,6 +111,26 @@ export async function POST(request: Request) {
throw new Error(data.error || 'フォームの送信に失敗しました。')
}

// 送信者へ確認メール(Resend)
const apiKey = process.env.RESEND_API_KEY
if (apiKey) {
try {
const resend = new Resend(apiKey)
const confirmHtml = `<div style="font-family:sans-serif;max-width:560px;color:#212529;"><p style="font-size:16px;line-height:1.6;">${body.name}様</p><p style="font-size:15px;line-height:1.6;">お問い合わせいただきありがとうございます。以下の内容で受け付けました。担当者より折り返しご連絡いたします。</p><hr style="border:none;border-top:1px solid #dee2e6;margin:20px 0;" /><p style="font-size:14px;color:#495057;"><strong>件名:</strong>${escapeHtml(body.subject)}</p><p style="font-size:14px;color:#495057;white-space:pre-wrap;"><strong>お問い合わせ内容:</strong><br />${escapeHtml(body.message)}</p><hr style="border:none;border-top:1px solid #dee2e6;margin:20px 0;" /><p style="font-size:12px;color:#868e96;">医者と歯医者の交換日記</p></div>`
const { error: sendError } = await resend.emails.send({
from: RESEND_FROM,
to: body.email,
subject: '【医者と歯医者の交換日記】お問い合わせを受け付けました',
html: confirmHtml,
})
if (sendError) {
console.warn('Contact confirmation email failed:', sendError.message)
}
} catch (confirmErr) {
console.warn('Contact confirmation email error:', confirmErr)
}
}

return createCorsResponse({ success: true })
} catch (error) {
console.error('❌ Contact form submission error:', error)
Expand Down
1 change: 1 addition & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default async function Home() {
fill
className="object-cover"
sizes="(max-width: 768px) 100vw, 50vw"
priority
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MedicalArticlesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function MedicalArticlesModal() {
href="/general"
className="inline-flex items-center justify-center rounded-lg border-2 border-gray-300 bg-white px-6 py-3 font-semibold text-[color:var(--foreground)] transition-colors hover:bg-gray-50"
>
いいえ
一般向けページに移動
</Link>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function NavLink({
<Link
href={href}
onClick={onClick}
suppressHydrationWarning
className={`flex items-center gap-1 px-3 py-2 text-sm font-medium transition-colors ${
isActive
? 'text-[color:var(--accent)]'
Expand Down Expand Up @@ -169,7 +170,6 @@ export function Header() {
)}
</div>
<NavLink href="/about" label="サイトについて" />
<NavLink href="/newsletter" label="メルマガ" />
</nav>

{/* Desktop Search Bar */}
Expand Down Expand Up @@ -225,7 +225,7 @@ export function Header() {
href="/newsletter"
className="hidden rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 xl:block"
>
メルマガ登録
医科歯科連携マニュアルDL
</Link>
</div>
</div>
Expand Down Expand Up @@ -271,7 +271,7 @@ export function Header() {
/>
<NavLink
href="/newsletter"
label="メルマガ"
label="医科歯科連携マニュアルDL"
onClick={() => setTimeout(() => setIsOpen(false), 30)}
/>
</nav>
Expand Down