General.svelte 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <script lang="ts">
  2. import { getBackendConfig, getWebhookUrl, updateWebhookUrl } from '$lib/apis';
  3. import { getAdminConfig, updateAdminConfig } from '$lib/apis/auths';
  4. import Switch from '$lib/components/common/Switch.svelte';
  5. import { config } from '$lib/stores';
  6. import { onMount, getContext } from 'svelte';
  7. import { toast } from 'svelte-sonner';
  8. const i18n = getContext('i18n');
  9. export let saveHandler: Function;
  10. let adminConfig = null;
  11. let webhookUrl = '';
  12. const updateHandler = async () => {
  13. webhookUrl = await updateWebhookUrl(localStorage.token, webhookUrl);
  14. const res = await updateAdminConfig(localStorage.token, adminConfig);
  15. if (res) {
  16. saveHandler();
  17. } else {
  18. toast.error(i18n.t('Failed to update settings'));
  19. }
  20. };
  21. onMount(async () => {
  22. await Promise.all([
  23. (async () => {
  24. adminConfig = await getAdminConfig(localStorage.token);
  25. })(),
  26. (async () => {
  27. webhookUrl = await getWebhookUrl(localStorage.token);
  28. })()
  29. ]);
  30. });
  31. </script>
  32. <form
  33. class="flex flex-col h-full justify-between space-y-3 text-sm"
  34. on:submit|preventDefault={async () => {
  35. updateHandler();
  36. }}
  37. >
  38. <div class=" space-y-3 overflow-y-scroll scrollbar-hidden h-full">
  39. {#if adminConfig !== null}
  40. <div>
  41. <div class=" mb-3 text-sm font-medium">{$i18n.t('General Settings')}</div>
  42. <div class=" flex w-full justify-between pr-2">
  43. <div class=" self-center text-xs font-medium">{$i18n.t('Enable New Sign Ups')}</div>
  44. <Switch bind:state={adminConfig.ENABLE_SIGNUP} />
  45. </div>
  46. <div class=" my-3 flex w-full justify-between">
  47. <div class=" self-center text-xs font-medium">{$i18n.t('Default User Role')}</div>
  48. <div class="flex items-center relative">
  49. <select
  50. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 text-xs bg-transparent outline-none text-right"
  51. bind:value={adminConfig.DEFAULT_USER_ROLE}
  52. placeholder="Select a role"
  53. >
  54. <option value="pending">{$i18n.t('pending')}</option>
  55. <option value="user">{$i18n.t('user')}</option>
  56. <option value="admin">{$i18n.t('admin')}</option>
  57. </select>
  58. </div>
  59. </div>
  60. <hr class=" dark:border-gray-850 my-2" />
  61. <div class="my-3 flex w-full items-center justify-between pr-2">
  62. <div class=" self-center text-xs font-medium">
  63. {$i18n.t('Show Admin Details in Account Pending Overlay')}
  64. </div>
  65. <Switch bind:state={adminConfig.SHOW_ADMIN_DETAILS} />
  66. </div>
  67. <div class="my-3 flex w-full items-center justify-between pr-2">
  68. <div class=" self-center text-xs font-medium">{$i18n.t('Enable Community Sharing')}</div>
  69. <Switch bind:state={adminConfig.ENABLE_COMMUNITY_SHARING} />
  70. </div>
  71. <div class="my-3 flex w-full items-center justify-between pr-2">
  72. <div class=" self-center text-xs font-medium">{$i18n.t('Enable Message Rating')}</div>
  73. <Switch bind:state={adminConfig.ENABLE_MESSAGE_RATING} />
  74. </div>
  75. <hr class=" dark:border-gray-850 my-2" />
  76. <div class=" w-full justify-between">
  77. <div class="flex w-full justify-between">
  78. <div class=" self-center text-xs font-medium">{$i18n.t('JWT Expiration')}</div>
  79. </div>
  80. <div class="flex mt-2 space-x-2">
  81. <input
  82. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  83. type="text"
  84. placeholder={`e.g.) "30m","1h", "10d". `}
  85. bind:value={adminConfig.JWT_EXPIRES_IN}
  86. />
  87. </div>
  88. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  89. {$i18n.t('Valid time units:')}
  90. <span class=" text-gray-300 font-medium"
  91. >{$i18n.t("'s', 'm', 'h', 'd', 'w' or '-1' for no expiration.")}</span
  92. >
  93. </div>
  94. </div>
  95. <hr class=" dark:border-gray-850 my-2" />
  96. <div class=" w-full justify-between">
  97. <div class="flex w-full justify-between">
  98. <div class=" self-center text-xs font-medium">{$i18n.t('Webhook URL')}</div>
  99. </div>
  100. <div class="flex mt-2 space-x-2">
  101. <input
  102. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  103. type="text"
  104. placeholder={`https://example.com/webhook`}
  105. bind:value={webhookUrl}
  106. />
  107. </div>
  108. </div>
  109. </div>
  110. {/if}
  111. </div>
  112. <div class="flex justify-end pt-3 text-sm font-medium">
  113. <button
  114. class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
  115. type="submit"
  116. >
  117. {$i18n.t('Save')}
  118. </button>
  119. </div>
  120. </form>