diff --git a/src/lib/elements/forms/index.ts b/src/lib/elements/forms/index.ts index e305bfb25..48988a2fe 100644 --- a/src/lib/elements/forms/index.ts +++ b/src/lib/elements/forms/index.ts @@ -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'; diff --git a/src/lib/elements/forms/inputPhone.svelte b/src/lib/elements/forms/inputPhone.svelte new file mode 100644 index 000000000..295b8474c --- /dev/null +++ b/src/lib/elements/forms/inputPhone.svelte @@ -0,0 +1,39 @@ + + + + +
+ +
+
diff --git a/src/routes/console/[project]/users/user/[user]/index.svelte b/src/routes/console/[project]/users/user/[user]/index.svelte index 13139ff44..d1398cc7f 100644 --- a/src/routes/console/[project]/users/user/[user]/index.svelte +++ b/src/routes/console/[project]/users/user/[user]/index.svelte @@ -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 + +
Update Phone
+ + + + + + + +
Update Password
diff --git a/src/service-worker.ts b/src/service-worker.ts index b2e01aaa3..84273f8d2 100644 --- a/src/service-worker.ts +++ b/src/service-worker.ts @@ -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') { diff --git a/tests/unit/elements/inputPhone.test.ts b/tests/unit/elements/inputPhone.test.ts new file mode 100644 index 000000000..ff180f4d8 --- /dev/null +++ b/tests/unit/elements/inputPhone.test.ts @@ -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'); +});