-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: require subscriptions for handles without numbers and for custo…
…m domains.
- Loading branch information
Showing
19 changed files
with
311 additions
and
55 deletions.
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
export const validUsernameRegex = /^([a-z0-9][_-]?){3,32}$/; | ||
export const validUnsubscribedUsernameRegex = /^([a-z0-9][_-]?){3,32}[0-9]{4}$/; | ||
|
||
export const validDomainRegex = /^([A-Za-z0-9-]{1,63}\.)+[A-Za-z]{2,12}(:[0-9]{1,5})?$/; | ||
|
||
export function genRandomUsernameSuffix() { | ||
return Math.floor(Math.random() * (9999 - 1000 + 1) + 1000).toString(); | ||
} |
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
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
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,10 @@ | ||
<script lang="ts"> | ||
import type { ActionData, PageData } from './$types'; | ||
import ClaimHandlePage from './components/ClaimHandlePage.svelte'; | ||
const { form, data }: { form: ActionData; data: PageData } = $props(); | ||
const action = '?/claimHandle'; | ||
</script> | ||
|
||
<ClaimHandlePage {form} {action} subscriptionInfo={data.subscriptionInfo} /> |
56 changes: 56 additions & 0 deletions
56
src/routes/(app)/claim-handle/components/ClaimHandleForm.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,56 @@ | ||
<script lang="ts"> | ||
import { env } from '$env/dynamic/public'; | ||
import type { UserSubscriptionInfo } from '$lib/billing'; | ||
import { genRandomUsernameSuffix } from '$lib/usernames/client'; | ||
import Icon from '@iconify/svelte'; | ||
const { | ||
error, | ||
action, | ||
subscriptionInfo | ||
}: { | ||
error: string | undefined; | ||
action: string; | ||
subscriptionInfo: UserSubscriptionInfo; | ||
} = $props(); | ||
let handle = $state(''); | ||
let randomNumberSuffix = $state(genRandomUsernameSuffix()); | ||
let fullHandleSuffix = $derived( | ||
(subscriptionInfo?.isSubscribed ? '' : randomNumberSuffix) + '.' + env.PUBLIC_USER_DOMAIN_PARENT | ||
); | ||
let handleWithSuffix = $derived( | ||
subscriptionInfo?.isSubscribed ? handle : handle + randomNumberSuffix | ||
); | ||
</script> | ||
|
||
<form class="card m-8 flex max-w-[40em] flex-col gap-4 p-6" method="post" {action}> | ||
<h1 class="text-2xl font-bold">Claim Handle</h1> | ||
|
||
{#if error} | ||
<aside class="alert variant-ghost-error w-80"> | ||
<div class="alert-message"> | ||
<p>{error}</p> | ||
</div> | ||
</aside> | ||
{/if} | ||
|
||
<p>Choose a handle for your Weird profile! You will be able to change this later.</p> | ||
|
||
{#if !subscriptionInfo?.isSubscribed} | ||
<p class="text- flex items-center gap-3 pb-4 text-secondary-200"> | ||
<Icon icon="material-symbols:error-outline" font-size={40} /> Your handle will end with a random | ||
4 digit number. Having a Weird subscription allows you to choose a name without the number. | ||
</p> | ||
{/if} | ||
|
||
<div class="input-group input-group-divider grid-cols-[auto_1fr_auto]"> | ||
<div class="input-group-shim">@</div> | ||
<input placeholder="handle" bind:value={handle} /> | ||
<input type="hidden" name="username" value={handleWithSuffix} /> | ||
<div class="input-group-shim"> | ||
{fullHandleSuffix} | ||
</div> | ||
</div> | ||
<button class="variant-ghost btn">Claim</button> | ||
</form> |
15 changes: 15 additions & 0 deletions
15
src/routes/(app)/claim-handle/components/ClaimHandlePage.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,15 @@ | ||
<script lang="ts"> | ||
import type { UserSubscriptionInfo } from '$lib/billing'; | ||
import ClaimHandleForm from './ClaimHandleForm.svelte'; | ||
const { | ||
form, | ||
action, | ||
subscriptionInfo | ||
}: { form: any; action: string; subscriptionInfo: UserSubscriptionInfo } = $props(); | ||
const error: string | undefined = form?.error; | ||
</script> | ||
|
||
<main class="flex flex-col items-center"> | ||
<ClaimHandleForm {error} {action} {subscriptionInfo} /> | ||
</main> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.