Users.svelte 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <script lang="ts">
  2. import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths';
  3. import { getUserPermissions, updateUserPermissions } from '$lib/apis/users';
  4. import { onMount } from 'svelte';
  5. export let saveHandler: Function;
  6. let permissions = {
  7. chat: {
  8. deletion: true
  9. }
  10. };
  11. onMount(async () => {
  12. permissions = await getUserPermissions(localStorage.token);
  13. });
  14. </script>
  15. <form
  16. class="flex flex-col h-full justify-between space-y-3 text-sm"
  17. on:submit|preventDefault={async () => {
  18. // console.log('submit');
  19. await updateUserPermissions(localStorage.token, permissions);
  20. saveHandler();
  21. }}
  22. >
  23. <div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-80">
  24. <div>
  25. <div class=" mb-2 text-sm font-medium">User Permissions</div>
  26. <div class=" flex w-full justify-between">
  27. <div class=" self-center text-xs font-medium">Allow Chat Deletion</div>
  28. <button
  29. class="p-1 px-3 text-xs flex rounded transition"
  30. on:click={() => {
  31. permissions.chat.deletion = !permissions.chat.deletion;
  32. }}
  33. type="button"
  34. >
  35. {#if permissions.chat.deletion}
  36. <svg
  37. xmlns="http://www.w3.org/2000/svg"
  38. viewBox="0 0 16 16"
  39. fill="currentColor"
  40. class="w-4 h-4"
  41. >
  42. <path
  43. d="M11.5 1A3.5 3.5 0 0 0 8 4.5V7H2.5A1.5 1.5 0 0 0 1 8.5v5A1.5 1.5 0 0 0 2.5 15h7a1.5 1.5 0 0 0 1.5-1.5v-5A1.5 1.5 0 0 0 9.5 7V4.5a2 2 0 1 1 4 0v1.75a.75.75 0 0 0 1.5 0V4.5A3.5 3.5 0 0 0 11.5 1Z"
  44. />
  45. </svg>
  46. <span class="ml-2 self-center">Allow</span>
  47. {:else}
  48. <svg
  49. xmlns="http://www.w3.org/2000/svg"
  50. viewBox="0 0 16 16"
  51. fill="currentColor"
  52. class="w-4 h-4"
  53. >
  54. <path
  55. fill-rule="evenodd"
  56. d="M8 1a3.5 3.5 0 0 0-3.5 3.5V7A1.5 1.5 0 0 0 3 8.5v5A1.5 1.5 0 0 0 4.5 15h7a1.5 1.5 0 0 0 1.5-1.5v-5A1.5 1.5 0 0 0 11.5 7V4.5A3.5 3.5 0 0 0 8 1Zm2 6V4.5a2 2 0 1 0-4 0V7h4Z"
  57. clip-rule="evenodd"
  58. />
  59. </svg>
  60. <span class="ml-2 self-center">Don't Allow</span>
  61. {/if}
  62. </button>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="flex justify-end pt-3 text-sm font-medium">
  67. <button
  68. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  69. type="submit"
  70. >
  71. Save
  72. </button>
  73. </div>
  74. </form>