Registrations.tsx 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { User } from '../../gql'
  2. import { useState } from 'react'
  3. const Registration = ({ registration }: { registration: User }) => {
  4. return (
  5. <li key={registration.id}>
  6. <button type='button' onClick={() => alert('not implemented.')}>
  7. delete
  8. </button>
  9. Registration: {registration.name}
  10. </li>
  11. )
  12. }
  13. const Registrations = ({
  14. registrations,
  15. className,
  16. }: {
  17. registrations?: User[]
  18. className: string
  19. }) => {
  20. const [show, setShow] = useState(false)
  21. return (
  22. <div className={className}>
  23. <h2>
  24. Registrations <span onClick={() => setShow(!show)}>({registrations?.length ?? 0})</span>
  25. </h2>
  26. {show &&
  27. (registrations?.length ? (
  28. <ul>
  29. {registrations.map((registration) => (
  30. <Registration registration={registration} />
  31. ))}
  32. </ul>
  33. ) : (
  34. <p>No registrations found.</p>
  35. ))}
  36. </div>
  37. )
  38. }
  39. export default Registrations