InAppNotificationForms.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { type JSX, useId } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import type { FilterType } from './InAppNotification';
  4. type InAppNotificationFormsProps = {
  5. isUnopendNotificationsVisible: boolean;
  6. onChangeUnopendNotificationsVisible: () => void;
  7. activeFilter: FilterType;
  8. onChangeFilter: (filter: FilterType) => void;
  9. };
  10. export const InAppNotificationForms = (
  11. props: InAppNotificationFormsProps,
  12. ): JSX.Element => {
  13. const {
  14. isUnopendNotificationsVisible,
  15. onChangeUnopendNotificationsVisible,
  16. activeFilter,
  17. onChangeFilter,
  18. } = props;
  19. const { t } = useTranslation('commons');
  20. const toggleId = useId();
  21. return (
  22. <div className="my-2">
  23. {/* Filter tabs */}
  24. <fieldset className="btn-group w-100 mb-2">
  25. <button
  26. type="button"
  27. className={`btn btn-sm ${activeFilter === 'all' ? 'btn-primary' : 'btn-outline-secondary'}`}
  28. onClick={() => onChangeFilter('all')}
  29. >
  30. {t('in_app_notification.filter_all')}
  31. </button>
  32. <button
  33. type="button"
  34. className={`btn btn-sm ${activeFilter === 'notifications' ? 'btn-primary' : 'btn-outline-secondary'}`}
  35. onClick={() => onChangeFilter('notifications')}
  36. >
  37. {t('in_app_notification.notifications')}
  38. </button>
  39. <button
  40. type="button"
  41. className={`btn btn-sm ${activeFilter === 'news' ? 'btn-primary' : 'btn-outline-secondary'}`}
  42. onClick={() => onChangeFilter('news')}
  43. >
  44. {t('in_app_notification.news')}
  45. </button>
  46. </fieldset>
  47. {/* Unread-only toggle */}
  48. <div className="form-check form-switch">
  49. <label className="form-check-label" htmlFor={toggleId}>
  50. {t('in_app_notification.only_unread')}
  51. </label>
  52. <input
  53. id={toggleId}
  54. className="form-check-input"
  55. type="checkbox"
  56. role="switch"
  57. aria-checked={isUnopendNotificationsVisible}
  58. checked={isUnopendNotificationsVisible}
  59. onChange={onChangeUnopendNotificationsVisible}
  60. />
  61. </div>
  62. </div>
  63. );
  64. };