-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
2158a71
commit 5dc04fa
Showing
11 changed files
with
117 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from hashid_field import rest as hidrest | ||
from rest_framework import serializers | ||
|
||
from . import models | ||
|
||
|
||
class WorkshopItemSerializer(serializers.ModelSerializer): | ||
id = hidrest.HashidSerializerCharField(source_field="workshops.WorkshopItem.id", read_only=True) | ||
name = serializers.CharField(min_length=10) | ||
|
||
class Meta: | ||
model = models.WorkshopItem | ||
fields = ('id', 'name') |
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
1 change: 1 addition & 0 deletions
1
packages/webapp/src/routes/workshops/workshopItemCreate/index.ts
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 @@ | ||
export { WorkshopItemCreate as default } from './workshopItemCreate.component'; |
47 changes: 47 additions & 0 deletions
47
packages/webapp/src/routes/workshops/workshopItemCreate/workshopItemCreate.component.tsx
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,47 @@ | ||
import { useMutation } from '@apollo/client'; | ||
import { gql } from '@sb/webapp-api-client'; | ||
import { useApiForm } from '@sb/webapp-api-client/hooks'; | ||
import { Input } from '@sb/webapp-core/components/forms'; | ||
import { FC } from 'react'; | ||
|
||
import { WorkshopItemFields } from './workshopItemCreate.types'; | ||
|
||
export const workshopItemCreateMutation = gql(/* GraphQL */ ` | ||
mutation WorkshopItemCreateMutation($input: WorkshopItemCreateMutationInput!) { | ||
createWorkshop(input: $input) { | ||
workshopItem { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`); | ||
|
||
export const WorkshopItemCreate: FC = () => { | ||
const { form, setApolloGraphQLResponseErrors } = useApiForm<WorkshopItemFields>({ | ||
defaultValues: { | ||
name: '', | ||
}, | ||
}); | ||
|
||
const [commitWorkshopItemCreateMutation] = useMutation(workshopItemCreateMutation); | ||
|
||
const onSubmit = async (formData: WorkshopItemFields) => { | ||
const { data, errors } = await commitWorkshopItemCreateMutation({ | ||
variables: { | ||
input: { | ||
name: formData.name, | ||
}, | ||
}, | ||
onError(error) { | ||
setApolloGraphQLResponseErrors(error.graphQLErrors); | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={form.handleSubmit(onSubmit)}> | ||
<Input {...form.register('name')} error={form.formState?.errors?.name?.message} /> | ||
</form> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/webapp/src/routes/workshops/workshopItemCreate/workshopItemCreate.types.ts
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,3 @@ | ||
export type WorkshopItemFields = { | ||
name: string; | ||
} |