Skip to content

Commit

Permalink
CPF-56 add Forbidden page, code cleanup for New Organization and Edit…
Browse files Browse the repository at this point in the history
… Organization forms
  • Loading branch information
Vikariusu committed Dec 29, 2023
1 parent 8cb8604 commit 6dbffad
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 31 deletions.
2 changes: 1 addition & 1 deletion api/src/graphql/organizations.sdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const schema = gql`
input: UpdateOrganizationInput!
): Organization! @requireAuth
deleteOrganization(id: Int!): Organization! @requireAuth
createOrgAgencyAdmin(
createOrganizationAgencyAdmin(
input: CreateOrgAgencyAdminInput!
): CreateOrgAgencyAdminPayload @requireAuth
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/services/organizations/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const createOrganization: MutationResolvers['createOrganization'] = ({
})
}

export const createOrgAgencyAdmin: MutationResolvers['createOrgAgencyAdmin'] =
export const createOrganizationAgencyAdmin: MutationResolvers['createOrganizationAgencyAdmin'] =
async ({ input }) => {
const {
organizationName,
Expand Down
14 changes: 7 additions & 7 deletions api/types/graphql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export type Mutation = {
createAgency: Agency;
createExpenditureCategory: ExpenditureCategory;
createInputTemplate: InputTemplate;
createOrgAgencyAdmin?: Maybe<CreateOrgAgencyAdminPayload>;
createOrganization: Organization;
createOrganizationAgencyAdmin?: Maybe<CreateOrgAgencyAdminPayload>;
createOutputTemplate: OutputTemplate;
createProject: Project;
createReportingPeriod: ReportingPeriod;
Expand Down Expand Up @@ -235,13 +235,13 @@ export type MutationcreateInputTemplateArgs = {
};


export type MutationcreateOrgAgencyAdminArgs = {
input: CreateOrgAgencyAdminInput;
export type MutationcreateOrganizationArgs = {
input: CreateOrganizationInput;
};


export type MutationcreateOrganizationArgs = {
input: CreateOrganizationInput;
export type MutationcreateOrganizationAgencyAdminArgs = {
input: CreateOrgAgencyAdminInput;
};


Expand Down Expand Up @@ -1060,8 +1060,8 @@ export type MutationResolvers<ContextType = RedwoodGraphQLContext, ParentType ex
createAgency: Resolver<ResolversTypes['Agency'], ParentType, ContextType, RequireFields<MutationcreateAgencyArgs, 'input'>>;
createExpenditureCategory: Resolver<ResolversTypes['ExpenditureCategory'], ParentType, ContextType, RequireFields<MutationcreateExpenditureCategoryArgs, 'input'>>;
createInputTemplate: Resolver<ResolversTypes['InputTemplate'], ParentType, ContextType, RequireFields<MutationcreateInputTemplateArgs, 'input'>>;
createOrgAgencyAdmin: Resolver<Maybe<ResolversTypes['CreateOrgAgencyAdminPayload']>, ParentType, ContextType, RequireFields<MutationcreateOrgAgencyAdminArgs, 'input'>>;
createOrganization: Resolver<ResolversTypes['Organization'], ParentType, ContextType, RequireFields<MutationcreateOrganizationArgs, 'input'>>;
createOrganizationAgencyAdmin: Resolver<Maybe<ResolversTypes['CreateOrgAgencyAdminPayload']>, ParentType, ContextType, RequireFields<MutationcreateOrganizationAgencyAdminArgs, 'input'>>;
createOutputTemplate: Resolver<ResolversTypes['OutputTemplate'], ParentType, ContextType, RequireFields<MutationcreateOutputTemplateArgs, 'input'>>;
createProject: Resolver<ResolversTypes['Project'], ParentType, ContextType, RequireFields<MutationcreateProjectArgs, 'input'>>;
createReportingPeriod: Resolver<ResolversTypes['ReportingPeriod'], ParentType, ContextType, RequireFields<MutationcreateReportingPeriodArgs, 'input'>>;
Expand Down Expand Up @@ -1100,8 +1100,8 @@ export type MutationRelationResolvers<ContextType = RedwoodGraphQLContext, Paren
createAgency?: RequiredResolverFn<ResolversTypes['Agency'], ParentType, ContextType, RequireFields<MutationcreateAgencyArgs, 'input'>>;
createExpenditureCategory?: RequiredResolverFn<ResolversTypes['ExpenditureCategory'], ParentType, ContextType, RequireFields<MutationcreateExpenditureCategoryArgs, 'input'>>;
createInputTemplate?: RequiredResolverFn<ResolversTypes['InputTemplate'], ParentType, ContextType, RequireFields<MutationcreateInputTemplateArgs, 'input'>>;
createOrgAgencyAdmin?: RequiredResolverFn<Maybe<ResolversTypes['CreateOrgAgencyAdminPayload']>, ParentType, ContextType, RequireFields<MutationcreateOrgAgencyAdminArgs, 'input'>>;
createOrganization?: RequiredResolverFn<ResolversTypes['Organization'], ParentType, ContextType, RequireFields<MutationcreateOrganizationArgs, 'input'>>;
createOrganizationAgencyAdmin?: RequiredResolverFn<Maybe<ResolversTypes['CreateOrgAgencyAdminPayload']>, ParentType, ContextType, RequireFields<MutationcreateOrganizationAgencyAdminArgs, 'input'>>;
createOutputTemplate?: RequiredResolverFn<ResolversTypes['OutputTemplate'], ParentType, ContextType, RequireFields<MutationcreateOutputTemplateArgs, 'input'>>;
createProject?: RequiredResolverFn<ResolversTypes['Project'], ParentType, ContextType, RequireFields<MutationcreateProjectArgs, 'input'>>;
createReportingPeriod?: RequiredResolverFn<ResolversTypes['ReportingPeriod'], ParentType, ContextType, RequireFields<MutationcreateReportingPeriodArgs, 'input'>>;
Expand Down
2 changes: 2 additions & 0 deletions web/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const Routes = () => {
<Route path="/organizations/{id:Int}" page={OrganizationOrganizationPage} name="organization" />
<Route path="/organizations" page={OrganizationOrganizationsPage} name="organizations" />
</PrivateSet>
{/* Forbidden page */}
<Route path="/forbidden" page={ForbiddenPage} name="forbidden" />
</PrivateSet>
<Route path="/login" page={LoginPage} name="login" />
<Route notfound page={NotFoundPage} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'

import OrganizationForm from 'src/components/Organization/OrganizationForm'
import EditOrganizationForm from 'src/components/Organization/EditOrganizationForm/EditOrganizationForm'

export const QUERY = gql`
query EditOrganizationById($id: Int!) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export const Success = ({
</h2>
</header>
<div className="rw-segment-main">
<OrganizationForm
<EditOrganizationForm
organization={organization}
onSave={onSave}
error={error}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import type { RWGqlError } from '@redwoodjs/forms'

type FormOrganization = NonNullable<EditOrganizationById['organization']>

interface OrganizationFormProps {
interface EditOrganizationFormProps {
organization?: EditOrganizationById['organization']
onSave: (data: UpdateOrganizationInput, id?: FormOrganization['id']) => void
error: RWGqlError
loading: boolean
}

const OrganizationForm = (props: OrganizationFormProps) => {
const EditOrganizationForm = (props: EditOrganizationFormProps) => {
const { organization, error, loading } = props
const formMethods: UseFormReturn<FormOrganization> =
useForm<FormOrganization>()
Expand Down Expand Up @@ -98,4 +98,4 @@ const OrganizationForm = (props: OrganizationFormProps) => {
)
}

export default OrganizationForm
export default EditOrganizationForm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import NewOrganizationForm from 'src/components/Organization/NewOrganizationForm

const CREATE_ORGANIZATION_AGENCY_ADMIN_MUTATION = gql`
mutation CreateOrgAgencyAdminMutation($input: CreateOrgAgencyAdminInput!) {
createOrgAgencyAdmin(input: $input) {
createOrganizationAgencyAdmin(input: $input) {
organization {
id
}
Expand Down Expand Up @@ -37,7 +37,7 @@ const NewOrganization = () => {
return (
<div className="rw-segment">
<header className="rw-segment-header">
<h2 className="rw-heading rw-heading-secondary">Organization</h2>
<h2 className="rw-heading rw-heading-secondary">Add Organization</h2>
</header>
<div className="rw-segment-main">
<NewOrganizationForm onSave={onSave} loading={loading} error={error} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button } from 'react-bootstrap'
import { useForm, UseFormReturn } from 'react-hook-form'
import type { EditOrganizationById } from 'types/graphql'
import type { CreateOrgAgencyAdminInput } from 'types/graphql'

import {
Form,
Expand All @@ -12,20 +12,17 @@ import {
} from '@redwoodjs/forms'
import type { RWGqlError } from '@redwoodjs/forms'

type FormOrganization = NonNullable<EditOrganizationById['organization']>

interface AddOrganizationFormProps {
organization?: EditOrganizationById['organization']
onSave: (data: any, id?: FormOrganization['id']) => void
interface NewOrganizationFormProps {
onSave: (data: CreateOrgAgencyAdminInput) => void
error: RWGqlError
loading: boolean
}

/*
This form creates a new organization, a new agency assigned to that organization,
and a new admin user assigned to that agency.
This form creates a new organization, assigns a new agency to that organization,
and assigns a new admin user to both the organization and the agency.
*/
const NewOrganizationForm = (props: AddOrganizationFormProps) => {
const NewOrganizationForm = (props: NewOrganizationFormProps) => {
const { onSave, error, loading } = props
const formMethods: UseFormReturn = useForm()
const hasErrors = Object.keys(formMethods.formState.errors).length > 0
Expand Down
13 changes: 13 additions & 0 deletions web/src/pages/ForbiddenPage/ForbiddenPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Meta, StoryObj } from '@storybook/react'

import ForbiddenPage from './ForbiddenPage'

const meta: Meta<typeof ForbiddenPage> = {
component: ForbiddenPage,
}

export default meta

type Story = StoryObj<typeof ForbiddenPage>

export const Primary: Story = {}
14 changes: 14 additions & 0 deletions web/src/pages/ForbiddenPage/ForbiddenPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { render } from '@redwoodjs/testing/web'

import ForbiddenPage from './ForbiddenPage'

// Improve this test with help from the Redwood Testing Doc:
// https://redwoodjs.com/docs/testing#testing-pages-layouts

describe('ForbiddenPage', () => {
it('renders successfully', () => {
expect(() => {
render(<ForbiddenPage />)
}).not.toThrow()
})
})
12 changes: 12 additions & 0 deletions web/src/pages/ForbiddenPage/ForbiddenPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MetaTags } from '@redwoodjs/web'

const ForbiddenPage = () => {
return (
<>
<MetaTags title="Forbidden" description="Forbidden page" />
<h2>Access to this page is restricted.</h2>
</>
)
}

export default ForbiddenPage
12 changes: 6 additions & 6 deletions web/types/graphql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ export type Mutation = {
createAgency: Agency;
createExpenditureCategory: ExpenditureCategory;
createInputTemplate: InputTemplate;
createOrgAgencyAdmin?: Maybe<CreateOrgAgencyAdminPayload>;
createOrganization: Organization;
createOrganizationAgencyAdmin?: Maybe<CreateOrgAgencyAdminPayload>;
createOutputTemplate: OutputTemplate;
createProject: Project;
createReportingPeriod: ReportingPeriod;
Expand Down Expand Up @@ -216,13 +216,13 @@ export type MutationcreateInputTemplateArgs = {
};


export type MutationcreateOrgAgencyAdminArgs = {
input: CreateOrgAgencyAdminInput;
export type MutationcreateOrganizationArgs = {
input: CreateOrganizationInput;
};


export type MutationcreateOrganizationArgs = {
input: CreateOrganizationInput;
export type MutationcreateOrganizationAgencyAdminArgs = {
input: CreateOrgAgencyAdminInput;
};


Expand Down Expand Up @@ -826,7 +826,7 @@ export type CreateOrgAgencyAdminMutationVariables = Exact<{
}>;


export type CreateOrgAgencyAdminMutation = { __typename?: 'Mutation', createOrgAgencyAdmin?: { __typename?: 'CreateOrgAgencyAdminPayload', organization?: { __typename?: 'Organization', id: number } | null } | null };
export type CreateOrgAgencyAdminMutation = { __typename?: 'Mutation', createOrganizationAgencyAdmin?: { __typename?: 'CreateOrgAgencyAdminPayload', organization?: { __typename?: 'Organization', id: number } | null } | null };

export type DeleteOrganizationMutationVariables = Exact<{
id: Scalars['Int'];
Expand Down

0 comments on commit 6dbffad

Please sign in to comment.