mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
Merge branch 'users' of github.com:appwrite/appwrite-console-poc into storage
This commit is contained in:
commit
89d8894629
5 files changed
+146
-5
No files matched your search
@@ -15,4 +15,5 @@ export { default as InputSearch } from './inputSearch.svelte';
|
||||
export { default as InputRadio } from './inputRadio.svelte';
|
||||
export { default as InputSelect } from './inputSelect.svelte';
|
||||
export { default as InputCheckbox } from './inputCheckbox.svelte';
|
||||
export { default as InputPhone } from './inputPhone.svelte';
|
||||
export { default as Helper } from './helper.svelte';
|
||||
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { FormItem } from '.';
|
||||
|
||||
export let label: string;
|
||||
export let id: string;
|
||||
export let value = '';
|
||||
export let placeholder = '';
|
||||
export let required = false;
|
||||
export let disabled = false;
|
||||
export let autofocus = false;
|
||||
export let autocomplete = true;
|
||||
export let maxlength: number = null;
|
||||
|
||||
let element: HTMLInputElement;
|
||||
|
||||
onMount(() => {
|
||||
if (element && autofocus) {
|
||||
element.focus();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<FormItem>
|
||||
<label class="label" for={id}>{label}</label>
|
||||
<div class="input-text-wrapper">
|
||||
<input
|
||||
{id}
|
||||
{placeholder}
|
||||
{disabled}
|
||||
{required}
|
||||
{maxlength}
|
||||
autocomplete={autocomplete ? 'on' : 'off'}
|
||||
type="tel"
|
||||
class="input-text"
|
||||
bind:value
|
||||
bind:this={element} />
|
||||
</div>
|
||||
</FormItem>
|
||||
@@ -3,7 +3,14 @@
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { Avatar, CardGrid, Box, DropList, DropListItem } from '$lib/components';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { Button, InputText, InputEmail, InputPassword, Helper } from '$lib/elements/forms';
|
||||
import {
|
||||
Button,
|
||||
InputText,
|
||||
InputEmail,
|
||||
InputPassword,
|
||||
InputPhone,
|
||||
Helper
|
||||
} from '$lib/elements/forms';
|
||||
import { Container } from '$lib/layout';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
@@ -19,11 +26,12 @@
|
||||
}
|
||||
}
|
||||
let showDelete = false;
|
||||
let showError: false | 'name' | 'email' | 'password' = false;
|
||||
let showError: false | 'name' | 'email' | 'phone' | 'password' = false;
|
||||
let errorMessage = 'Something went wrong';
|
||||
let errorType: 'error' | 'warning' | 'success' = 'error';
|
||||
let userName: string = null,
|
||||
userEmail: string = null,
|
||||
userPhone: string = null,
|
||||
newPassword: string = null,
|
||||
newPref = false,
|
||||
newKey: string = null,
|
||||
@@ -129,6 +137,20 @@
|
||||
addError('email', error.message, 'error');
|
||||
}
|
||||
}
|
||||
async function updatePhone() {
|
||||
try {
|
||||
await sdkForProject.users.updatePhone($user.response.$id, userPhone);
|
||||
$user.response.phone = userPhone;
|
||||
userPhone = null;
|
||||
showError = false;
|
||||
addNotification({
|
||||
message: 'Phone has been updated',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addError('phone', error.message, 'error');
|
||||
}
|
||||
}
|
||||
async function updatePassword() {
|
||||
try {
|
||||
await sdkForProject.users.updatePassword($user.response.$id, newPassword);
|
||||
@@ -303,6 +325,30 @@
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Update Phone</h6>
|
||||
<svelte:fragment slot="aside">
|
||||
<ul>
|
||||
<InputPhone
|
||||
id="phone"
|
||||
label="Phone"
|
||||
placeholder={$user.response.phone || '+4915739638796'}
|
||||
autocomplete={false}
|
||||
bind:value={userPhone} />
|
||||
{#if showError === 'phone'}
|
||||
<Helper type={errorType}>{errorMessage}</Helper>
|
||||
{/if}
|
||||
</ul>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
disabled={!userPhone}
|
||||
on:click={() => {
|
||||
updatePhone();
|
||||
}}>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
<CardGrid>
|
||||
<div>
|
||||
<h6 class="heading-level-7">Update Password</h6>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { version, build } from '$service-worker';
|
||||
import { version, build, files } from '$service-worker';
|
||||
|
||||
const name = `cache-${version}`;
|
||||
const cachedFiles = [...build, ...files];
|
||||
|
||||
self.addEventListener('install', (event: ExtendableEvent) => {
|
||||
event.waitUntil(caches.open(name).then((cache) => cache.addAll(build)));
|
||||
event.waitUntil(caches.open(name).then((cache) => cache.addAll(cachedFiles)));
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event: ExtendableEvent) => {
|
||||
@@ -24,7 +25,7 @@ self.addEventListener('fetch', (event: FetchEvent) => {
|
||||
const url = new URL(request.url);
|
||||
const cached = caches.match(request);
|
||||
|
||||
if (url.origin === location.origin && build.includes(url.pathname)) {
|
||||
if (url.origin === location.origin && cachedFiles.includes(url.pathname)) {
|
||||
// always return build files from cache
|
||||
event.respondWith(cached);
|
||||
} else if (url.protocol === 'https:' || location.hostname === 'localhost') {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import { render } from '@testing-library/svelte';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { InputPhone } from '../../../src/lib/elements/forms';
|
||||
|
||||
test('shows phone input', () => {
|
||||
const { getByText, getByLabelText } = render(InputPhone, { id: 'input', label: 'input' });
|
||||
const input = getByLabelText('input');
|
||||
|
||||
expect(getByText('input')).toBeInTheDocument();
|
||||
expect(input).toBeInTheDocument();
|
||||
expect(input).toHaveAttribute('type', 'tel');
|
||||
});
|
||||
|
||||
test('shows phone input - required', () => {
|
||||
const { getByLabelText } = render(InputPhone, { id: 'input', label: 'input', required: true });
|
||||
|
||||
expect(getByLabelText('input')).toBeRequired();
|
||||
});
|
||||
|
||||
test('shows phone input - disabled', () => {
|
||||
const { getByLabelText } = render(InputPhone, { id: 'input', label: 'input', disabled: true });
|
||||
|
||||
expect(getByLabelText('input')).toBeDisabled();
|
||||
});
|
||||
|
||||
test('shows phone input - autofocus', () => {
|
||||
const { getByLabelText } = render(InputPhone, { id: 'input', label: 'input', autofocus: true });
|
||||
|
||||
expect(getByLabelText('input')).toHaveFocus();
|
||||
});
|
||||
|
||||
test('shows phone input - placeholder', () => {
|
||||
const { getByPlaceholderText } = render(InputPhone, {
|
||||
id: 'input',
|
||||
label: 'input',
|
||||
placeholder: 'find me'
|
||||
});
|
||||
|
||||
expect(getByPlaceholderText('find me')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('state', async () => {
|
||||
const { component, getByLabelText } = render(InputPhone, {
|
||||
id: 'input',
|
||||
label: 'input',
|
||||
value: ''
|
||||
});
|
||||
const input = getByLabelText('input');
|
||||
|
||||
expect(component.value).toEqual('');
|
||||
await userEvent.type(input, 'lorem');
|
||||
expect(component.value).toEqual('lorem');
|
||||
});
|
||||
Reference in new issue
Block a user