ValvesModal.svelte 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { createEventDispatcher } from 'svelte';
  4. import { onMount, getContext } from 'svelte';
  5. import { addUser } from '$lib/apis/auths';
  6. import Modal from '../common/Modal.svelte';
  7. const i18n = getContext('i18n');
  8. const dispatch = createEventDispatcher();
  9. export let show = false;
  10. export let type = 'tool';
  11. export let id = null;
  12. let loading = false;
  13. let _user = {
  14. name: '',
  15. email: '',
  16. password: '',
  17. role: 'user'
  18. };
  19. const submitHandler = async () => {
  20. const stopLoading = () => {
  21. dispatch('save');
  22. loading = false;
  23. };
  24. };
  25. </script>
  26. <Modal size="sm" bind:show>
  27. <div>
  28. <div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
  29. <div class=" text-lg font-medium self-center">{$i18n.t('Valves')}</div>
  30. <button
  31. class="self-center"
  32. on:click={() => {
  33. show = false;
  34. }}
  35. >
  36. <svg
  37. xmlns="http://www.w3.org/2000/svg"
  38. viewBox="0 0 20 20"
  39. fill="currentColor"
  40. class="w-5 h-5"
  41. >
  42. <path
  43. 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"
  44. />
  45. </svg>
  46. </button>
  47. </div>
  48. <div class="flex flex-col md:flex-row w-full px-5 pb-4 md:space-x-4 dark:text-gray-200">
  49. <div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
  50. <form
  51. class="flex flex-col w-full"
  52. on:submit|preventDefault={() => {
  53. submitHandler();
  54. }}
  55. >
  56. <div class="px-1">
  57. <div class="flex flex-col w-full">
  58. <div class=" mb-1 text-xs text-gray-500">{$i18n.t('Role')}</div>
  59. <div class="flex-1">
  60. <select
  61. class="w-full capitalize rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 disabled:text-gray-500 dark:disabled:text-gray-500 outline-none"
  62. bind:value={_user.role}
  63. placeholder={$i18n.t('Enter Your Role')}
  64. required
  65. >
  66. <option value="pending"> {$i18n.t('pending')} </option>
  67. <option value="user"> {$i18n.t('user')} </option>
  68. <option value="admin"> {$i18n.t('admin')} </option>
  69. </select>
  70. </div>
  71. </div>
  72. <div class="flex flex-col w-full mt-2">
  73. <div class=" mb-1 text-xs text-gray-500">{$i18n.t('Name')}</div>
  74. <div class="flex-1">
  75. <input
  76. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 disabled:text-gray-500 dark:disabled:text-gray-500 outline-none"
  77. type="text"
  78. bind:value={_user.name}
  79. placeholder={$i18n.t('Enter Your Full Name')}
  80. autocomplete="off"
  81. required
  82. />
  83. </div>
  84. </div>
  85. <hr class=" dark:border-gray-800 my-3 w-full" />
  86. <div class="flex flex-col w-full">
  87. <div class=" mb-1 text-xs text-gray-500">{$i18n.t('Email')}</div>
  88. <div class="flex-1">
  89. <input
  90. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 disabled:text-gray-500 dark:disabled:text-gray-500 outline-none"
  91. type="email"
  92. bind:value={_user.email}
  93. placeholder={$i18n.t('Enter Your Email')}
  94. autocomplete="off"
  95. required
  96. />
  97. </div>
  98. </div>
  99. <div class="flex flex-col w-full mt-2">
  100. <div class=" mb-1 text-xs text-gray-500">{$i18n.t('Password')}</div>
  101. <div class="flex-1">
  102. <input
  103. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 disabled:text-gray-500 dark:disabled:text-gray-500 outline-none"
  104. type="password"
  105. bind:value={_user.password}
  106. placeholder={$i18n.t('Enter Your Password')}
  107. autocomplete="off"
  108. />
  109. </div>
  110. </div>
  111. </div>
  112. <div class="flex justify-end pt-3 text-sm font-medium">
  113. <button
  114. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg flex flex-row space-x-1 items-center {loading
  115. ? ' cursor-not-allowed'
  116. : ''}"
  117. type="submit"
  118. disabled={loading}
  119. >
  120. {$i18n.t('Submit')}
  121. {#if loading}
  122. <div class="ml-2 self-center">
  123. <svg
  124. class=" w-4 h-4"
  125. viewBox="0 0 24 24"
  126. fill="currentColor"
  127. xmlns="http://www.w3.org/2000/svg"
  128. ><style>
  129. .spinner_ajPY {
  130. transform-origin: center;
  131. animation: spinner_AtaB 0.75s infinite linear;
  132. }
  133. @keyframes spinner_AtaB {
  134. 100% {
  135. transform: rotate(360deg);
  136. }
  137. }
  138. </style><path
  139. 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"
  140. opacity=".25"
  141. /><path
  142. 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"
  143. class="spinner_ajPY"
  144. /></svg
  145. >
  146. </div>
  147. {/if}
  148. </button>
  149. </div>
  150. </form>
  151. </div>
  152. </div>
  153. </div>
  154. </Modal>
  155. <style>
  156. input::-webkit-outer-spin-button,
  157. input::-webkit-inner-spin-button {
  158. /* display: none; <- Crashes Chrome on hover */
  159. -webkit-appearance: none;
  160. margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
  161. }
  162. .tabs::-webkit-scrollbar {
  163. display: none; /* for Chrome, Safari and Opera */
  164. }
  165. .tabs {
  166. -ms-overflow-style: none; /* IE and Edge */
  167. scrollbar-width: none; /* Firefox */
  168. }
  169. input[type='number'] {
  170. -moz-appearance: textfield; /* Firefox */
  171. }
  172. </style>