PersonalSettings.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import React, { useMemo } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import CustomNavAndContents from '../CustomNavigation/CustomNavAndContents';
  4. import ApiSettings from './ApiSettings';
  5. // import { EditorSettings } from './EditorSettings';
  6. import ExternalAccountLinkedMe from './ExternalAccountLinkedMe';
  7. import InAppNotificationSettings from './InAppNotificationSettings';
  8. import OtherSettings from './OtherSettings';
  9. import PasswordSettings from './PasswordSettings';
  10. import UserSettings from './UserSettings';
  11. const UserInformationIcon = () => (
  12. <span
  13. data-testid="user-infomation-tab-button"
  14. className="material-symbols-outlined"
  15. >
  16. person
  17. </span>
  18. );
  19. const ExternalAccountsIcon = () => (
  20. <span
  21. data-testid="external-accounts-tab-button"
  22. className="material-symbols-outlined"
  23. >
  24. ungroup
  25. </span>
  26. );
  27. const PasswordSettingsIcon = () => (
  28. <span
  29. data-testid="password-settings-tab-button"
  30. className="material-symbols-outlined"
  31. >
  32. password
  33. </span>
  34. );
  35. const ApiSettingsIcon = () => (
  36. <span
  37. data-testid="api-settings-tab-button"
  38. className="material-symbols-outlined"
  39. >
  40. api
  41. </span>
  42. );
  43. const InAppNotificationSettingsIcon = () => (
  44. <span
  45. data-testid="in-app-notification-settings-tab-button"
  46. className="material-symbols-outlined"
  47. >
  48. notifications
  49. </span>
  50. );
  51. const OtherSettingsIcon = () => (
  52. <span
  53. data-testid="other-settings-tab-button"
  54. className="material-symbols-outlined"
  55. >
  56. settings
  57. </span>
  58. );
  59. const PersonalSettings = () => {
  60. const { t } = useTranslation();
  61. const navTabMapping = useMemo(() => {
  62. return {
  63. user_infomation: {
  64. Icon: UserInformationIcon,
  65. Content: UserSettings,
  66. i18n: t('User Information'),
  67. },
  68. external_accounts: {
  69. Icon: ExternalAccountsIcon,
  70. Content: ExternalAccountLinkedMe,
  71. i18n: t('admin:user_management.external_accounts'),
  72. },
  73. password_settings: {
  74. Icon: PasswordSettingsIcon,
  75. Content: PasswordSettings,
  76. i18n: t('Password Settings'),
  77. },
  78. api_settings: {
  79. Icon: ApiSettingsIcon,
  80. Content: ApiSettings,
  81. i18n: t('API Settings'),
  82. },
  83. // editor_settings: {
  84. // Icon: () => <span className="material-symbols-outlined">edit</span>,
  85. // Content: EditorSettings,
  86. // i18n: t('editor_settings.editor_settings'),
  87. // },
  88. in_app_notification_settings: {
  89. Icon: InAppNotificationSettingsIcon,
  90. Content: InAppNotificationSettings,
  91. i18n: t('in_app_notification_settings.in_app_notification_settings'),
  92. },
  93. other_settings: {
  94. Icon: OtherSettingsIcon,
  95. Content: OtherSettings,
  96. i18n: t('Other Settings'),
  97. },
  98. };
  99. }, [t]);
  100. const getDefaultTabIndex = () => {
  101. // e.g) '/me#password_settings' sets password settings tab as default
  102. const tab = window.location.hash?.substring(1);
  103. let defaultTabIndex;
  104. Object.keys(navTabMapping).forEach((key, i) => {
  105. if (key === tab) {
  106. defaultTabIndex = i;
  107. }
  108. });
  109. return defaultTabIndex;
  110. };
  111. return (
  112. <div data-testid="grw-personal-settings">
  113. <CustomNavAndContents
  114. defaultTabIndex={getDefaultTabIndex()}
  115. navTabMapping={navTabMapping}
  116. navigationMode="both"
  117. tabContentClasses={['px-0']}
  118. />
  119. </div>
  120. );
  121. };
  122. export default PersonalSettings;