|
@@ -7,27 +7,37 @@
|
|
|
export let saveText = 'Criar usuário';
|
|
export let saveText = 'Criar usuário';
|
|
|
export let cancelText = 'Cancelar';
|
|
export let cancelText = 'Cancelar';
|
|
|
|
|
|
|
|
- let nome = '';
|
|
|
|
|
|
|
+ let name = '';
|
|
|
let email = '';
|
|
let email = '';
|
|
|
- let role = 'user';
|
|
|
|
|
let password = '';
|
|
let password = '';
|
|
|
let confirmPassword = '';
|
|
let confirmPassword = '';
|
|
|
|
|
+ let phone = '';
|
|
|
|
|
+ let cpf = '';
|
|
|
|
|
+ let birthdate = '';
|
|
|
|
|
+ let address = '';
|
|
|
|
|
+ let city = '';
|
|
|
|
|
+ let state = '';
|
|
|
|
|
+ let zip = '';
|
|
|
|
|
+ let country = 'BR';
|
|
|
|
|
+ let kyc = false;
|
|
|
|
|
|
|
|
- let errors = { nome: '', email: '', password: '', confirmPassword: '' };
|
|
|
|
|
|
|
+ let errors = { name: '', email: '', password: '', confirmPassword: '' };
|
|
|
|
|
|
|
|
function validate() {
|
|
function validate() {
|
|
|
- errors = { nome: '', email: '', password: '', confirmPassword: '' };
|
|
|
|
|
|
|
+ errors = { name: '', email: '', password: '', confirmPassword: '' };
|
|
|
const emailRegex = /[^@\s]+@[^@\s]+\.[^@\s]+/;
|
|
const emailRegex = /[^@\s]+@[^@\s]+\.[^@\s]+/;
|
|
|
- if (!nome.trim()) errors.nome = 'Informe o nome';
|
|
|
|
|
|
|
+ if (!name.trim()) errors.name = 'Informe o nome';
|
|
|
if (!email || !emailRegex.test(email)) errors.email = 'Informe um e-mail válido';
|
|
if (!email || !emailRegex.test(email)) errors.email = 'Informe um e-mail válido';
|
|
|
if (!password || password.length < 6) errors.password = 'Senha mínima de 6 caracteres';
|
|
if (!password || password.length < 6) errors.password = 'Senha mínima de 6 caracteres';
|
|
|
if (confirmPassword !== password) errors.confirmPassword = 'Confirmação diferente da senha';
|
|
if (confirmPassword !== password) errors.confirmPassword = 'Confirmação diferente da senha';
|
|
|
- return !errors.nome && !errors.email && !errors.password && !errors.confirmPassword;
|
|
|
|
|
|
|
+ return !errors.name && !errors.email && !errors.password && !errors.confirmPassword;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function handleSave() {
|
|
function handleSave() {
|
|
|
if (!validate()) return;
|
|
if (!validate()) return;
|
|
|
- dispatch('submit', { nome, email, role, password });
|
|
|
|
|
|
|
+ const birthdateNum = birthdate ? Number(birthdate.replace(/-/g, '')) : undefined;
|
|
|
|
|
+ const kycNum = kyc ? 1 : 0;
|
|
|
|
|
+ dispatch('submit', { name, email, password, phone, address, city, state, zip, country, kyc: kycNum, birthdate: birthdateNum, cpf });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function handleCancel() {
|
|
function handleCancel() {
|
|
@@ -48,12 +58,12 @@
|
|
|
<div>
|
|
<div>
|
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Nome</label>
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Nome</label>
|
|
|
<input
|
|
<input
|
|
|
- bind:value={nome}
|
|
|
|
|
|
|
+ bind:value={name}
|
|
|
class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
placeholder="Nome completo"
|
|
placeholder="Nome completo"
|
|
|
/>
|
|
/>
|
|
|
- {#if errors.nome}
|
|
|
|
|
- <p class="mt-1 text-sm text-red-600">{errors.nome}</p>
|
|
|
|
|
|
|
+ {#if errors.name}
|
|
|
|
|
+ <p class="mt-1 text-sm text-red-600">{errors.name}</p>
|
|
|
{/if}
|
|
{/if}
|
|
|
</div>
|
|
</div>
|
|
|
<div>
|
|
<div>
|
|
@@ -70,37 +80,113 @@
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
|
|
|
- <div>
|
|
|
|
|
- <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Perfil</label>
|
|
|
|
|
- <select bind:value={role} class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
|
|
|
|
|
- <option value="user">Usuário</option>
|
|
|
|
|
- <option value="admin">Administrador</option>
|
|
|
|
|
- </select>
|
|
|
|
|
|
|
+ <div class="space-y-4">
|
|
|
|
|
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Telefone</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={phone}
|
|
|
|
|
+ type="tel"
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="+55 11 99999-9999"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">CPF</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={cpf}
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="123.456.789-00"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Data de Nascimento</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={birthdate}
|
|
|
|
|
+ type="date"
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
- <div>
|
|
|
|
|
- <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Senha</label>
|
|
|
|
|
- <input
|
|
|
|
|
- bind:value={password}
|
|
|
|
|
- type="password"
|
|
|
|
|
- class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
- placeholder="********"
|
|
|
|
|
- />
|
|
|
|
|
- {#if errors.password}
|
|
|
|
|
- <p class="mt-1 text-sm text-red-600">{errors.password}</p>
|
|
|
|
|
- {/if}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Endereço</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={address}
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="Av. Paulista, 1000"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Cidade</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={city}
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="São Paulo"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Estado</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={state}
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="SP"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">CEP</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={zip}
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="01310-100"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">País</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={country}
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="BR"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Senha</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={password}
|
|
|
|
|
+ type="password"
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="********"
|
|
|
|
|
+ />
|
|
|
|
|
+ {#if errors.password}
|
|
|
|
|
+ <p class="mt-1 text-sm text-red-600">{errors.password}</p>
|
|
|
|
|
+ {/if}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Confirmar senha</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ bind:value={confirmPassword}
|
|
|
|
|
+ type="password"
|
|
|
|
|
+ class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
+ placeholder="********"
|
|
|
|
|
+ />
|
|
|
|
|
+ {#if errors.confirmPassword}
|
|
|
|
|
+ <p class="mt-1 text-sm text-red-600">{errors.confirmPassword}</p>
|
|
|
|
|
+ {/if}
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+
|
|
|
<div>
|
|
<div>
|
|
|
- <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Confirmar senha</label>
|
|
|
|
|
- <input
|
|
|
|
|
- bind:value={confirmPassword}
|
|
|
|
|
- type="password"
|
|
|
|
|
- class="mt-1 block w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
|
|
- placeholder="********"
|
|
|
|
|
- />
|
|
|
|
|
- {#if errors.confirmPassword}
|
|
|
|
|
- <p class="mt-1 text-sm text-red-600">{errors.confirmPassword}</p>
|
|
|
|
|
- {/if}
|
|
|
|
|
|
|
+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">KYC verificado</label>
|
|
|
|
|
+ <div class="mt-2">
|
|
|
|
|
+ <input type="checkbox" bind:checked={kyc} class="rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500" />
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|