AddGroupModal.svelte 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { getContext, onMount } from 'svelte';
  4. const i18n = getContext('i18n');
  5. import Modal from '$lib/components/common/Modal.svelte';
  6. import Textarea from '$lib/components/common/Textarea.svelte';
  7. export let onSubmit: Function = () => {};
  8. export let show = false;
  9. let name = '';
  10. let description = '';
  11. let userIds = [];
  12. let loading = false;
  13. const submitHandler = async () => {
  14. loading = true;
  15. const group = {
  16. name,
  17. description
  18. };
  19. await onSubmit(group);
  20. loading = false;
  21. show = false;
  22. name = '';
  23. description = '';
  24. userIds = [];
  25. };
  26. onMount(() => {
  27. console.log('mounted');
  28. });
  29. </script>
  30. <Modal size="sm" bind:show>
  31. <div>
  32. <div class=" flex justify-between dark:text-gray-100 px-5 pt-4 mb-1.5">
  33. <div class=" text-lg font-medium self-center font-primary">
  34. {$i18n.t('Add User Group')}
  35. </div>
  36. <button
  37. class="self-center"
  38. on:click={() => {
  39. show = false;
  40. }}
  41. >
  42. <svg
  43. xmlns="http://www.w3.org/2000/svg"
  44. viewBox="0 0 20 20"
  45. fill="currentColor"
  46. class="w-5 h-5"
  47. >
  48. <path
  49. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  50. />
  51. </svg>
  52. </button>
  53. </div>
  54. <div class="flex flex-col md:flex-row w-full px-4 pb-4 md:space-x-4 dark:text-gray-200">
  55. <div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
  56. <form
  57. class="flex flex-col w-full"
  58. on:submit={(e) => {
  59. e.preventDefault();
  60. submitHandler();
  61. }}
  62. >
  63. <div class="px-1 flex flex-col w-full">
  64. <div class="flex gap-2">
  65. <div class="flex flex-col w-full">
  66. <div class=" mb-0.5 text-xs text-gray-500">{$i18n.t('Name')}</div>
  67. <div class="flex-1">
  68. <input
  69. class="w-full text-sm bg-transparent placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none"
  70. type="text"
  71. bind:value={name}
  72. placeholder={$i18n.t('Group Name')}
  73. autocomplete="off"
  74. required
  75. />
  76. </div>
  77. </div>
  78. </div>
  79. <div class="flex flex-col w-full mt-2">
  80. <div class=" mb-1 text-xs text-gray-500">{$i18n.t('Description')}</div>
  81. <div class="flex-1">
  82. <Textarea
  83. className="w-full text-sm bg-transparent placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none resize-none"
  84. rows={2}
  85. bind:value={description}
  86. placeholder={$i18n.t('Group Description')}
  87. />
  88. </div>
  89. </div>
  90. </div>
  91. <div class="flex justify-end pt-3 text-sm font-medium gap-1.5">
  92. <button
  93. 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 flex flex-row space-x-1 items-center {loading
  94. ? ' cursor-not-allowed'
  95. : ''}"
  96. type="submit"
  97. disabled={loading}
  98. >
  99. {$i18n.t('Create')}
  100. {#if loading}
  101. <div class="ml-2 self-center">
  102. <svg
  103. class=" w-4 h-4"
  104. viewBox="0 0 24 24"
  105. fill="currentColor"
  106. xmlns="http://www.w3.org/2000/svg"
  107. ><style>
  108. .spinner_ajPY {
  109. transform-origin: center;
  110. animation: spinner_AtaB 0.75s infinite linear;
  111. }
  112. @keyframes spinner_AtaB {
  113. 100% {
  114. transform: rotate(360deg);
  115. }
  116. }
  117. </style><path
  118. d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
  119. opacity=".25"
  120. /><path
  121. d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
  122. class="spinner_ajPY"
  123. /></svg
  124. >
  125. </div>
  126. {/if}
  127. </button>
  128. </div>
  129. </form>
  130. </div>
  131. </div>
  132. </div>
  133. </Modal>