TermsDialog.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use client';
  2. import { useState, useEffect } from 'react';
  3. import {
  4. DialogContent,
  5. DialogDescription,
  6. DialogFooter,
  7. DialogHeader,
  8. DialogTitle,
  9. DialogClose
  10. } from '@/components/ui/dialog';
  11. import { fetchApi } from '@/lib/utils/client';
  12. import type { DocumentResponse } from '@/types/response/page/document';
  13. export default function TermsDialog({ subject, code }: { subject: string; code: string }) {
  14. const [content, setContent] = useState<string | null>(null);
  15. const [loading, setLoading] = useState(true);
  16. useEffect(() => {
  17. fetchApi<DocumentResponse>(`/api/document/${code}`)
  18. .then((res) => {
  19. if (res.success && res.data) {
  20. setContent(res.data.content);
  21. }
  22. })
  23. .finally(() => setLoading(false));
  24. }, [code]);
  25. return (
  26. <DialogContent className='sm:max-w-[600px] max-h-[80vh]'>
  27. <DialogHeader>
  28. <DialogTitle>{subject}</DialogTitle>
  29. <DialogDescription asChild>
  30. <div className='mt-2 max-h-[60vh] overflow-y-auto text-sm'>
  31. {loading ? (
  32. <p className='text-center py-4'>준비 중...</p>
  33. ) : content ? (
  34. <section dangerouslySetInnerHTML={{ __html: content }} />
  35. ) : (
  36. <p className='text-center py-4'>내용이 없습니다.</p>
  37. )}
  38. </div>
  39. </DialogDescription>
  40. </DialogHeader>
  41. <DialogFooter className='sm:justify-center'>
  42. <DialogClose asChild>
  43. <button type='button' className='btn btn-default w-1/2'>확인</button>
  44. </DialogClose>
  45. </DialogFooter>
  46. </DialogContent>
  47. );
  48. }