-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Mock numbers #798
Merged
Merged
Feat: Mock numbers #798
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
24f6921
feat: initial commit
christyjacob4 cd28d85
chore: linter
christyjacob4 2ab338f
Merge branch 'main' of https://github.com/appwrite/console into mock-…
christyjacob4 7019113
chore: sync and updates
christyjacob4 6f6520c
chore: update the key value UI
christyjacob4 4c34327
chore: fix reactivity
christyjacob4 77cf2a7
chore: remove unused import
christyjacob4 d0f00d5
chore: update conditions
christyjacob4 06dcab0
chore: update conditions
christyjacob4 c474e6a
Apply suggestions from code review
christyjacob4 b9e64b7
fix: review comments
christyjacob4 760b664
fix: review comments
christyjacob4 48b9538
chore: linter
christyjacob4 e9ed380
chore: remove imput
christyjacob4 bbcb239
Merge branch '1.6.x' of github.com:appwrite/console into mock-phone-n…
ArmanNik fe04939
feat: update sdk and small fixes
ArmanNik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { type Client, type Models } from '@appwrite.io/console'; | ||
|
||
export type MockNumber = { | ||
phone: string; | ||
otp: string; | ||
}; | ||
|
||
export type Project = Models.Project & { | ||
authMockNumbers: MockNumber[]; | ||
}; | ||
|
||
export class Auth { | ||
client: Client; | ||
|
||
constructor(client: Client) { | ||
this.client = client; | ||
} | ||
|
||
async updateMockNumbers(projectId: string, numbers: MockNumber[]): Promise<Project> { | ||
const path = `/projects/${projectId}/auth/mock-numbers`; | ||
const params = { | ||
projectId, | ||
numbers: numbers | ||
}; | ||
const uri = new URL(this.client.config.endpoint + path); | ||
return await this.client.call( | ||
'patch', | ||
uri, | ||
{ | ||
'content-type': 'application/json' | ||
}, | ||
params | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/routes/console/project-[project]/auth/security/updateMockNumbers.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<script lang="ts"> | ||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; | ||
import { CardGrid, Heading } from '$lib/components'; | ||
import { InputPhone, InputText } from '$lib/elements/forms'; | ||
import { Button, Form, FormItem, FormItemPart } from '$lib/elements/forms'; | ||
import type { MockNumber } from '$lib/sdk/auth'; | ||
import { sdk } from '$lib/stores/sdk'; | ||
import { project } from '../../store'; | ||
import { addNotification } from '$lib/stores/notifications'; | ||
import { invalidate } from '$app/navigation'; | ||
import { Dependencies } from '$lib/constants'; | ||
import { writable } from 'svelte/store'; | ||
import Empty from '$lib/components/empty.svelte'; | ||
|
||
const numbers = writable<MockNumber[]>($project.authMockNumbers); | ||
let initialNumbers = []; | ||
let projectId: string = $project.$id; | ||
let submitDisabled = true; | ||
|
||
$: initialNumbers = $project.authMockNumbers.map((num) => ({ ...num })); | ||
$: submitDisabled = JSON.stringify($numbers) === JSON.stringify(initialNumbers); | ||
TorstenDittmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async function updateMockNumbers() { | ||
try { | ||
await sdk.forConsole.auth.updateMockNumbers(projectId, $numbers); | ||
await invalidate(Dependencies.PROJECT); | ||
addNotification({ | ||
type: 'success', | ||
message: 'Updated mock phone numbers successfully' | ||
}); | ||
trackEvent(Submit.AuthMockNumbersUpdate); | ||
} catch (error) { | ||
addNotification({ | ||
type: 'error', | ||
message: error.message | ||
}); | ||
trackError(error, Submit.AuthMockNumbersUpdate); | ||
} | ||
} | ||
|
||
function addPhoneNumber(number: MockNumber) { | ||
numbers.update((n) => [ | ||
...n, | ||
{ | ||
phone: number.phone, | ||
otp: number.otp | ||
} | ||
]); | ||
} | ||
|
||
function deletePhoneNumber(index: number) { | ||
numbers.update((n) => { | ||
n.splice(index, 1); | ||
return n; | ||
}); | ||
} | ||
</script> | ||
|
||
<Form onSubmit={updateMockNumbers}> | ||
<CardGrid> | ||
<Heading tag="h6" size="7" id="variables">Mock Phone Numbers</Heading> | ||
<p> | ||
Generate <b>fictional</b> numbers to simulate phone verification while testing demo accounts. | ||
A maximum of 10 phone numbers can be generated. | ||
</p> | ||
|
||
<svelte:fragment slot="aside"> | ||
{#if $numbers.length > 0} | ||
<ul class="form-list"> | ||
{#each $numbers as number, index} | ||
<FormItem isMultiple> | ||
<InputPhone | ||
id={`key-${index}`} | ||
bind:value={number.phone} | ||
fullWidth | ||
placeholder="Enter Phone Number" | ||
label="Phone Number" | ||
showLabel={index === 0 ? true : false} | ||
maxlength={16} | ||
required /> | ||
<InputText | ||
id={`value-${index}`} | ||
bind:value={number.otp} | ||
fullWidth | ||
placeholder="Enter value" | ||
label="Verification Code" | ||
showLabel={index === 0 ? true : false} | ||
maxlength={6} | ||
required /> | ||
<FormItemPart alignEnd> | ||
<Button | ||
text | ||
disabled={$numbers.length === 0} | ||
on:click={() => { | ||
deletePhoneNumber(index); | ||
}}> | ||
<span class="icon-x" aria-hidden="true" /> | ||
</Button> | ||
</FormItemPart> | ||
</FormItem> | ||
{/each} | ||
</ul> | ||
{#if $numbers.length < 10} | ||
<Button | ||
noMargin | ||
text | ||
on:click={() => | ||
addPhoneNumber({ | ||
phone: '', | ||
otp: '' | ||
})} | ||
disabled={$numbers.length >= 10}> | ||
<span class="icon-plus" aria-hidden="true" /> | ||
<span class="text">Add number</span> | ||
</Button> | ||
{/if} | ||
{:else} | ||
<Empty | ||
on:click={() => { | ||
addPhoneNumber({ | ||
phone: '', | ||
otp: '' | ||
}); | ||
}}>Create a mock phone number</Empty> | ||
{/if} | ||
</svelte:fragment> | ||
|
||
<svelte:fragment slot="actions"> | ||
<Button disabled={submitDisabled} submit>Update</Button> | ||
</svelte:fragment> | ||
</CardGrid> | ||
</Form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TorstenDittmann is there a way to combine this into the projects class ? Because that is where this method is supposed to be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once the spec is generated and a sdk is released it will be automatically part of that 👍🏻