Skip to content

Commit

Permalink
add create org page
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Jun 13, 2024
1 parent 0637c0e commit e801d4a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ the [Linguistics Institute at Payap University](https://li.payap.ac.th/) in Chia
"created_at": "Created",
"members": "Members"
},
"create": {
"title": "Create Organization",
"name": "Name",
"name_missing": "Organization name required",
"submit": "Create Organization",
}
},
"project": {
"create": {
Expand Down
38 changes: 38 additions & 0 deletions frontend/src/routes/(authenticated)/org/create/+page.svelte
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>
22 changes: 22 additions & 0 deletions frontend/src/routes/(authenticated)/org/create/+page.ts
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;
}

0 comments on commit e801d4a

Please sign in to comment.