Skip to content

Commit

Permalink
Workshop #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pziemkowski committed Nov 27, 2023
1 parent 2158a71 commit 5dc04fa
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/backend/apps/workshops/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from graphene import relay
from graphene_django import DjangoObjectType

from . import models
from common.graphql import mutations
from . import models, serializers


class WorkshopItemType(DjangoObjectType):
Expand All @@ -24,3 +25,11 @@ class Query(graphene.ObjectType):
@staticmethod
def resolve_all_workshop_items(root, info, **kwargs):
return models.WorkshopItem.objects.all()


class WorkshopItemCreateMutation(mutations.CreateModelMutation):
class Meta:
serializer_class = serializers.WorkshopItemSerializer

class Mutation(graphene.ObjectType):
create_workshop = WorkshopItemCreateMutation.Field()
13 changes: 13 additions & 0 deletions packages/backend/apps/workshops/serializers.py
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')
1 change: 1 addition & 0 deletions packages/backend/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
users_schema.Mutation,
finances_schema.Mutation,
integrations_schema.Mutation,
workshops_schema.Mutation,
]
),
subscription=graphql_subscription(([notifications_schema.Subscription])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ type FileFieldType {
name: String
}
type ApiMutation {
createWorkshop(input: WorkshopItemCreateMutationInput!): WorkshopItemCreateMutationPayload
generateSaasIdeas(input: GenerateSaasIdeasMutationInput!): GenerateSaasIdeasMutationPayload
changeActiveSubscription(input: ChangeActiveSubscriptionMutationInput!): ChangeActiveSubscriptionMutationPayload
cancelActiveSubscription(input: CancelActiveSubscriptionMutationInput!): CancelActiveSubscriptionMutationPayload
Expand Down Expand Up @@ -758,6 +759,10 @@ type ApiMutation {
createFavoriteContentfulDemoItem(input: CreateFavoriteContentfulDemoItemMutationInput!): CreateFavoriteContentfulDemoItemMutationPayload
deleteFavoriteContentfulDemoItem(input: DeleteFavoriteContentfulDemoItemMutationInput!): DeleteFavoriteContentfulDemoItemMutationPayload
}
type WorkshopItemCreateMutationPayload {
workshopItem: WorkshopItemType
clientMutationId: String
}
type GenerateSaasIdeasMutationPayload {
ideas: [String]
clientMutationId: String
Expand Down Expand Up @@ -1366,6 +1371,10 @@ enum DjstripeSetupIntentUsageChoices {
"On session"
ON_SESSION
}
input WorkshopItemCreateMutationInput {
name: String!
clientMutationId: String
}
input GenerateSaasIdeasMutationInput {
keywords: [String]
clientMutationId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const documents = {
"\n fragment notificationsListContentFragment on Query {\n hasUnreadNotifications\n allNotifications(first: $count, after: $cursor) {\n edges {\n node {\n id\n data\n createdAt\n readAt\n type\n issuer {\n id\n avatar\n email\n }\n }\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n }\n": types.NotificationsListContentFragmentFragmentDoc,
"\n mutation notificationsListMarkAsReadMutation($input: MarkReadAllNotificationsMutationInput!) {\n markReadAllNotifications(input: $input) {\n ok\n }\n }\n": types.NotificationsListMarkAsReadMutationDocument,
"\n mutation authConfirmUserEmailMutation($input: ConfirmEmailMutationInput!) {\n confirm(input: $input) {\n ok\n }\n }\n": types.AuthConfirmUserEmailMutationDocument,
"\n mutation WorkshopItemCreateMutation($input: WorkshopItemCreateMutationInput!) {\n createWorkshop(input: $input) {\n workshopItem {\n id\n name\n }\n }\n }\n": types.WorkshopItemCreateMutationDocument,
"\n query WorkshopItemsList {\n allWorkshopItems {\n edges {\n node {\n id\n name\n }\n }\n }\n }\n": types.WorkshopItemsListDocument,
"\n mutation authChangePasswordMutation($input: ChangePasswordMutationInput!) {\n changePassword(input: $input) {\n access\n refresh\n }\n }\n": types.AuthChangePasswordMutationDocument,
"\n mutation authUpdateUserProfileMutation($input: UpdateCurrentUserMutationInput!) {\n updateCurrentUser(input: $input) {\n userProfile {\n id\n user {\n ...commonQueryCurrentUserFragment\n }\n }\n }\n }\n": types.AuthUpdateUserProfileMutationDocument,
Expand Down Expand Up @@ -290,6 +291,10 @@ export function gql(source: "\n mutation notificationsListMarkAsReadMutation($i
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(source: "\n mutation authConfirmUserEmailMutation($input: ConfirmEmailMutationInput!) {\n confirm(input: $input) {\n ok\n }\n }\n"): (typeof documents)["\n mutation authConfirmUserEmailMutation($input: ConfirmEmailMutationInput!) {\n confirm(input: $input) {\n ok\n }\n }\n"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(source: "\n mutation WorkshopItemCreateMutation($input: WorkshopItemCreateMutationInput!) {\n createWorkshop(input: $input) {\n workshopItem {\n id\n name\n }\n }\n }\n"): (typeof documents)["\n mutation WorkshopItemCreateMutation($input: WorkshopItemCreateMutationInput!) {\n createWorkshop(input: $input) {\n workshopItem {\n id\n name\n }\n }\n }\n"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type ApiMutation = {
createFavoriteContentfulDemoItem?: Maybe<CreateFavoriteContentfulDemoItemMutationPayload>;
createPaymentIntent?: Maybe<CreatePaymentIntentMutationPayload>;
createSetupIntent?: Maybe<CreateSetupIntentMutationPayload>;
createWorkshop?: Maybe<WorkshopItemCreateMutationPayload>;
deleteCrudDemoItem?: Maybe<DeleteCrudDemoItemMutationPayload>;
deleteDocumentDemoItem?: Maybe<DeleteDocumentDemoItemMutationPayload>;
deleteFavoriteContentfulDemoItem?: Maybe<DeleteFavoriteContentfulDemoItemMutationPayload>;
Expand Down Expand Up @@ -133,6 +134,11 @@ export type ApiMutationCreateSetupIntentArgs = {
};


export type ApiMutationCreateWorkshopArgs = {
input: WorkshopItemCreateMutationInput;
};


export type ApiMutationDeleteCrudDemoItemArgs = {
input: DeleteCrudDemoItemMutationInput;
};
Expand Down Expand Up @@ -2666,6 +2672,17 @@ export type WorkshopItemConnection = {
pageInfo: PageInfo;
};

export type WorkshopItemCreateMutationInput = {
clientMutationId?: InputMaybe<Scalars['String']['input']>;
name: Scalars['String']['input'];
};

export type WorkshopItemCreateMutationPayload = {
__typename?: 'WorkshopItemCreateMutationPayload';
clientMutationId?: Maybe<Scalars['String']['output']>;
workshopItem?: Maybe<WorkshopItemType>;
};

/** A Relay edge containing a `WorkshopItem` and its cursor. */
export type WorkshopItemEdge = {
__typename?: 'WorkshopItemEdge';
Expand Down Expand Up @@ -3030,6 +3047,13 @@ export type AuthConfirmUserEmailMutationMutationVariables = Exact<{

export type AuthConfirmUserEmailMutationMutation = { __typename?: 'ApiMutation', confirm?: { __typename?: 'ConfirmEmailMutationPayload', ok?: boolean | null } | null };

export type WorkshopItemCreateMutationMutationVariables = Exact<{
input: WorkshopItemCreateMutationInput;
}>;


export type WorkshopItemCreateMutationMutation = { __typename?: 'ApiMutation', createWorkshop?: { __typename?: 'WorkshopItemCreateMutationPayload', workshopItem?: { __typename?: 'WorkshopItemType', id: string, name: string } | null } | null };

export type WorkshopItemsListQueryVariables = Exact<{ [key: string]: never; }>;


Expand Down Expand Up @@ -3160,6 +3184,7 @@ export const NotificationsListQueryDocument = {"kind":"Document","definitions":[
export const NotificationsListSubscriptionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"subscription","name":{"kind":"Name","value":"notificationsListSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"notificationCreated"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"readAt"}},{"kind":"Field","name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"issuer"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"avatar"}},{"kind":"Field","name":{"kind":"Name","value":"email"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<NotificationsListSubscriptionSubscription, NotificationsListSubscriptionSubscriptionVariables>;
export const NotificationsListMarkAsReadMutationDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"notificationsListMarkAsReadMutation"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"MarkReadAllNotificationsMutationInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"markReadAllNotifications"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ok"}}]}}]}}]} as unknown as DocumentNode<NotificationsListMarkAsReadMutationMutation, NotificationsListMarkAsReadMutationMutationVariables>;
export const AuthConfirmUserEmailMutationDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"authConfirmUserEmailMutation"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ConfirmEmailMutationInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"confirm"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ok"}}]}}]}}]} as unknown as DocumentNode<AuthConfirmUserEmailMutationMutation, AuthConfirmUserEmailMutationMutationVariables>;
export const WorkshopItemCreateMutationDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"WorkshopItemCreateMutation"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"WorkshopItemCreateMutationInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createWorkshop"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"workshopItem"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]} as unknown as DocumentNode<WorkshopItemCreateMutationMutation, WorkshopItemCreateMutationMutationVariables>;
export const WorkshopItemsListDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"WorkshopItemsList"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"allWorkshopItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}}]} as unknown as DocumentNode<WorkshopItemsListQuery, WorkshopItemsListQueryVariables>;
export const AuthChangePasswordMutationDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"authChangePasswordMutation"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ChangePasswordMutationInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"changePassword"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"access"}},{"kind":"Field","name":{"kind":"Name","value":"refresh"}}]}}]}}]} as unknown as DocumentNode<AuthChangePasswordMutationMutation, AuthChangePasswordMutationMutationVariables>;
export const AuthUpdateUserProfileMutationDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"authUpdateUserProfileMutation"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateCurrentUserMutationInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateCurrentUser"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"userProfile"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"user"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"commonQueryCurrentUserFragment"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"commonQueryCurrentUserFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CurrentUserType"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"email"}},{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}},{"kind":"Field","name":{"kind":"Name","value":"roles"}},{"kind":"Field","name":{"kind":"Name","value":"avatar"}},{"kind":"Field","name":{"kind":"Name","value":"otpVerified"}},{"kind":"Field","name":{"kind":"Name","value":"otpEnabled"}}]}}]} as unknown as DocumentNode<AuthUpdateUserProfileMutationMutation, AuthUpdateUserProfileMutationMutationVariables>;
Expand Down
3 changes: 2 additions & 1 deletion packages/webapp/src/app/app.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Admin } from '../routes/admin';
import { PasswordReset } from '../routes/auth/passwordReset';
import ValidateOtp from '../routes/auth/validateOtp';
import { AnonymousRoute, AuthRoute } from '../shared/components/routes';
import { ConfirmEmail, Home, Login, Logout, NotFound, Profile, Signup, WorkshopItemsList } from './asyncComponents';
import { ConfirmEmail, Home, Login, Logout, NotFound, Profile, Signup, WorkshopItemsList, WorkshopItemCreate } from './asyncComponents';
import { LANG_PREFIX, RoutesConfig } from './config/routes';
import { ValidRoutesProviders } from './providers';

Expand Down Expand Up @@ -66,6 +66,7 @@ export const App = () => {
<Route path={RoutesConfig.documents} element={<Documents />} />
<Route path={RoutesConfig.saasIdeas} element={<SaasIdeas />} />
<Route path={RoutesConfig.workshops.list} element={<WorkshopItemsList />} />
<Route path={RoutesConfig.workshops.create} element={<WorkshopItemCreate />} />
<Route path="*" element={<NotFound />} />
</Route>
<Route path={LANG_PREFIX} element={<AuthRoute allowedRoles={Role.ADMIN} />}>
Expand Down
1 change: 1 addition & 0 deletions packages/webapp/src/app/asyncComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const Profile = asyncComponent(() => import('../routes/profile'));
export const ConfirmEmail = asyncComponent(() => import('../routes/auth/confirmEmail'));

export const WorkshopItemsList = asyncComponent(() => import('../routes/workshops/workshopItemsList'));
export const WorkshopItemCreate = asyncComponent(() => import('../routes/workshops/workshopItemCreate'));
//<-- IMPORT ROUTE -->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { WorkshopItemCreate as default } from './workshopItemCreate.component';
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>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type WorkshopItemFields = {
name: string;
}

0 comments on commit 5dc04fa

Please sign in to comment.