-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 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
38 changes: 38 additions & 0 deletions
38
frontend/src/routes/(authenticated)/org/create/+page.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,38 @@ | ||
<script lang="ts"> | ||
import t from '$lib/i18n'; | ||
import {TitlePage} from '$lib/layout'; | ||
import {Form, FormError, Input, lexSuperForm, SubmitButton} from '$lib/forms'; | ||
import {z} from 'zod'; | ||
import {goto} from '$app/navigation'; | ||
import {_createOrg} from './+page'; | ||
const formSchema = z.object({ | ||
name: z.string().trim().min(1, $t('org.create.name_missing')), | ||
}); | ||
let {form, errors, message, enhance, submitting} = lexSuperForm(formSchema, async () => { | ||
const result = await _createOrg({ | ||
name: $form.name, | ||
}); | ||
if (result.error) { | ||
$message = result.error.message; | ||
} else { | ||
await goto(`/org/${result.data?.createOrganization.organization?.id}`); | ||
} | ||
}); | ||
</script> | ||
|
||
<TitlePage title={$t('org.create.title')}> | ||
<Form {enhance}> | ||
<Input | ||
label={$t('org.create.name')} | ||
bind:value={$form.name} | ||
error={$errors.name} | ||
autofocus | ||
/> | ||
|
||
<FormError error={$message}/> | ||
<SubmitButton loading={$submitting}> | ||
{$t('org.create.submit')} | ||
</SubmitButton> | ||
</Form> | ||
</TitlePage> |
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,22 @@ | ||
import {getClient, graphql} from '$lib/gql'; | ||
import type {CreateOrganizationInput, CreateOrgMutation} from '$lib/gql/generated/graphql'; | ||
import type {$OpResult} from '$lib/gql/types'; | ||
|
||
export async function _createOrg(input: CreateOrganizationInput): $OpResult<CreateOrgMutation> { | ||
const result = await getClient().mutation( | ||
graphql(` | ||
mutation createOrg($input: CreateOrganizationInput!) { | ||
createOrganization(input: $input) { | ||
organization { | ||
id | ||
} | ||
errors { | ||
... on DbError { | ||
code | ||
} | ||
} | ||
} | ||
} | ||
`), {input}); | ||
return result; | ||
} |