Skip to content

Commit

Permalink
Merge pull request #547 from open-formulieren/chore/restructure-appoi…
Browse files Browse the repository at this point in the history
…ntments-code

🚚 Group appointment components for more logical code organization
  • Loading branch information
SilviaAmAm authored Sep 14, 2023
2 parents e2000aa + 62047a4 commit 1f47894
Show file tree
Hide file tree
Showing 35 changed files with 59 additions and 55 deletions.
12 changes: 6 additions & 6 deletions src/components/appointments/CreateAppointment/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import SummaryConfirmation from 'components/SummaryConfirmation';
import {ValidationError} from 'errors';
import useTitle from 'hooks/useTitle';

import {getContactDetailsFields} from '../ContactDetailsStep';
import {fieldLabel as dateLabel} from '../DateSelect';
import {getLocations, fieldLabel as locationLabel} from '../LocationSelect';
import {amountLabel} from '../Product';
import {getAllProducts, fieldLabel as productLabel} from '../ProductSelect';
import {fieldLabel as timeLabel} from '../TimeSelect';
import {fieldLabel as dateLabel} from '../fields/DateSelect';
import {getLocations, fieldLabel as locationLabel} from '../fields/LocationSelect';
import {amountLabel} from '../fields/Product';
import {getAllProducts, fieldLabel as productLabel} from '../fields/ProductSelect';
import {fieldLabel as timeLabel} from '../fields/TimeSelect';
import {getContactDetailsFields} from '../steps/ContactDetailsStep';
import {useCreateAppointmentContext} from './CreateAppointmentState';

const createAppointment = async (baseUrl, submission, appointmentData, statementValues) => {
Expand Down
4 changes: 1 addition & 3 deletions src/components/appointments/CreateAppointment/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import {Navigate, matchPath, resolvePath} from 'react-router-dom';

import useQuery from 'hooks/useQuery';

import ChooseProductStep from '../ChooseProductStep';
import ContactDetailsStep from '../ContactDetailsStep';
import LocationAndTimeStep from '../LocationAndTimeStep';
import {ChooseProductStep, ContactDetailsStep, LocationAndTimeStep} from '../steps';
import Confirmation from './Confirmation';
import Summary from './Summary';

Expand Down
3 changes: 1 addition & 2 deletions src/components/appointments/ManageAppointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {Route, Routes} from 'react-router-dom';
import ErrorBoundary from 'components/ErrorBoundary';
import {LayoutColumn} from 'components/Layout';

import CancelAppointment from './CancelAppointment';
import CancelAppointmentSuccess from './CancelAppointmentSuccess';
import {CancelAppointment, CancelAppointmentSuccess} from './cancel';

// with react router v6, these routes can be hoisted into the App if we'd like to

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {withRouter} from 'storybook-addon-react-router-v6';
import Card from 'components/Card';
import {ConfigDecorator, LayoutDecorator} from 'story-utils/decorators';

import {mockAppointmentCancelErrorPost, mockAppointmentCancelPost} from '../mocks';
import CancelAppointment from './CancelAppointment';
import {mockAppointmentCancelErrorPost, mockAppointmentCancelPost} from './mocks';

export default {
title: 'Private API / Appointments / Cancellation / Cancel',
Expand Down
2 changes: 2 additions & 0 deletions src/components/appointments/cancel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {default as CancelAppointment} from './CancelAppointment';
export {default as CancelAppointmentSuccess} from './CancelAppointmentSuccess';
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {ConfigContext} from 'Context';
import {get} from 'api';
import {DateField} from 'components/forms';

import {ProductsType} from './types';
import {prepareProductsForProductIDQuery} from './utils';
import {ProductsType} from '../types';
import {prepareProductsForProductIDQuery} from '../utils';

export const fieldLabel = defineMessage({
description: 'Appoinments: appointment date label',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {ConfigContext} from 'Context';
import {BASE_URL} from 'api-mocks';
import mswServer from 'api-mocks/msw-server';

import {mockAppointmentDatesGet} from '../mocks';
import DateSelect from './DateSelect';
import {mockAppointmentDatesGet} from './mocks';

const waitForPosition = () => act(async () => {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {userEvent, within} from '@storybook/testing-library';

import {ConfigDecorator, FormikDecorator} from 'story-utils/decorators';

import {mockAppointmentDatesGet} from '../mocks';
import DateSelect from './DateSelect';
import {mockAppointmentDatesGet} from './mocks';

export default {
title: 'Private API / Appointments / Fields / DateSelect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {get} from 'api';
import {getCached, setCached} from 'cache';
import {AsyncSelectField} from 'components/forms';

import {ProductsType} from './types';
import {ProductsType} from '../types';

// TODO: use a nicer widget/form field than select

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {userEvent, waitFor, within} from '@storybook/testing-library';

import {ConfigDecorator, FormikDecorator} from 'story-utils/decorators';

import {mockAppointmentLocationsGet} from '../mocks';
import LocationSelect from './LocationSelect';
import {mockAppointmentLocationsGet} from './mocks';

export default {
title: 'Private API / Appointments / Fields / LocationSelect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {defineMessage, useIntl} from 'react-intl';

import {NumberField} from 'components/forms';

import {AppointmentConfigContext} from './Context';
import {AppointmentConfigContext} from '../Context';
import {ProductsType} from '../types';
import ProductSelect from './ProductSelect';
import {ProductsType} from './types';

export const amountLabel = defineMessage({
description: 'Appointments: product amount field label',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {userEvent, within} from '@storybook/testing-library';

import {ConfigDecorator, FormikDecorator} from 'story-utils/decorators';

import {AppointmentConfigContext} from './Context';
import {AppointmentConfigContext} from '../Context';
import {mockAppointmentProductsGet} from '../mocks';
import Product from './Product';
import {mockAppointmentProductsGet} from './mocks';

const PRODUCTS_DATA = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {get} from 'api';
import {getCached, setCached} from 'cache';
import {AsyncSelectField} from 'components/forms';

import {ProductsType} from './types';
import {ProductsType} from '../types';

const CACHED_PRODUCTS_KEY = 'appointment|all-products';
const CACHED_PRODUCTS_MAX_AGE_MS = 15 * 60 * 1000; // 15 minutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {userEvent, within} from '@storybook/testing-library';

import {ConfigDecorator, FormikDecorator} from 'story-utils/decorators';

import {mockAppointmentProductsGet} from '../mocks';
import {default as ProductSelectComponent} from './ProductSelect';
import {mockAppointmentProductsGet} from './mocks';

export default {
title: 'Private API / Appointments / Fields / ProductSelect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {get} from 'api';
import {AsyncSelectField} from 'components/forms';
import {useCalendarLocale} from 'components/forms/DateField';

import {ProductsType} from './types';
import {prepareProductsForProductIDQuery} from './utils';
import {ProductsType} from '../types';
import {prepareProductsForProductIDQuery} from '../utils';

export const fieldLabel = defineMessage({
description: 'Appoinments: time select label',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {addDays, formatISO} from 'date-fns';

import {ConfigDecorator, FormikDecorator} from 'story-utils/decorators';

import {mockAppointmentTimesGet} from '../mocks';
import TimeSelect from './TimeSelect';
import {mockAppointmentTimesGet} from './mocks';

const tomorrow = formatISO(addDays(new Date(), 1), {representation: 'date'});

Expand Down
4 changes: 4 additions & 0 deletions src/components/appointments/fields/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {default as DateSelect} from './DateSelect';
export {default as LocationSelect} from './LocationSelect';
export {default as Product} from './Product';
export {default as TimeSelect} from './TimeSelect';
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import useQuery from 'hooks/useQuery';
import useTitle from 'hooks/useTitle';
import {getBEMClassName} from 'utils';

import {AppointmentConfigContext} from './Context';
import {useCreateAppointmentContext} from './CreateAppointment/CreateAppointmentState';
import Product from './Product';
import SubmitRow from './SubmitRow';
import {AppointmentConfigContext} from '../Context';
import {useCreateAppointmentContext} from '../CreateAppointment/CreateAppointmentState';
import SubmitRow from '../SubmitRow';
import {Product} from '../fields';

const productSchema = z
.array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {ConfigContext} from 'Context';
import {BASE_URL, buildSubmission} from 'api-mocks';
import mswServer from 'api-mocks/msw-server';

import {CreateAppointmentContext} from '../Context';
import {buildContextValue} from '../CreateAppointment/CreateAppointmentState';
import {mockAppointmentProductsGet} from '../mocks';
import ChooseProductStep from './ChooseProductStep';
import {CreateAppointmentContext} from './Context';
import {buildContextValue} from './CreateAppointment/CreateAppointmentState';
import {mockAppointmentProductsGet} from './mocks';

const render = () => {
const appointmentContext = buildContextValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {withRouter} from 'storybook-addon-react-router-v6';

import {ConfigDecorator, LayoutDecorator, withCard} from 'story-utils/decorators';

import {AppointmentConfigContext} from '../Context';
import {mockAppointmentProductsGet} from '../mocks';
import {withAppointmentState} from '../story-utils';
import ChooseProductStep from './ChooseProductStep';
import {AppointmentConfigContext} from './Context';
import {mockAppointmentProductsGet} from './mocks';
import {withAppointmentState} from './story-utils';

export default {
title: 'Private API / Appointments / Steps / 1 - Choose product',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import Loader from 'components/Loader';
import {FormioComponent, getEmptyValue, getSchema} from 'components/formio';
import useTitle from 'hooks/useTitle';

import {useCreateAppointmentContext} from './CreateAppointment/CreateAppointmentState';
import SubmitRow from './SubmitRow';
import {useCreateAppointmentContext} from '../CreateAppointment/CreateAppointmentState';
import SubmitRow from '../SubmitRow';

const CACHED_CONTACT_DETAILS_FIELDS_KEY = 'appointments|contactDetailsFields';
const CACHED_CONTACT_DETAILS_FIELDS_MAX_AGE_MS = 15 * 60 * 1000; // 15 minutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {withRouter} from 'storybook-addon-react-router-v6';

import {ConfigDecorator, LayoutDecorator, withCard} from 'story-utils/decorators';

import {mockAppointmentCustomerFieldsGet} from '../mocks';
import {withAppointmentState} from '../story-utils';
import ContactDetailsStep from './ContactDetailsStep';
import {mockAppointmentCustomerFieldsGet} from './mocks';
import {withAppointmentState} from './story-utils';

const TOMORROW = formatISO(addDays(new Date(), 1), {representation: 'date'});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import {CardTitle} from 'components/Card';
import Loader from 'components/Loader';
import useTitle from 'hooks/useTitle';

import {useCreateAppointmentContext} from './CreateAppointment/CreateAppointmentState';
import DateSelect from './DateSelect';
import LocationSelect from './LocationSelect';
import {getAllProducts} from './ProductSelect';
import SubmitRow from './SubmitRow';
import TimeSelect from './TimeSelect';
import {ProductsType} from './types';
import {useCreateAppointmentContext} from '../CreateAppointment/CreateAppointmentState';
import SubmitRow from '../SubmitRow';
import {DateSelect, LocationSelect, TimeSelect} from '../fields';
import {getAllProducts} from '../fields/ProductSelect';
import {ProductsType} from '../types';

const schema = z.object({
location: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {ConfigContext} from 'Context';
import {BASE_URL, buildSubmission} from 'api-mocks';
import mswServer from 'api-mocks/msw-server';

import {CreateAppointmentContext} from './Context';
import {buildContextValue} from './CreateAppointment/CreateAppointmentState';
import LocationAndTimeStep from './LocationAndTimeStep';
import {CreateAppointmentContext} from '../Context';
import {buildContextValue} from '../CreateAppointment/CreateAppointmentState';
import {
mockAppointmentDatesGet,
mockAppointmentLocationsGet,
mockAppointmentProductsGet,
mockAppointmentTimesGet,
} from './mocks';
} from '../mocks';
import LocationAndTimeStep from './LocationAndTimeStep';

const render = initialValues => {
const {products, ...stepData} = initialValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {withRouter} from 'storybook-addon-react-router-v6';

import {ConfigDecorator, LayoutDecorator, withCard} from 'story-utils/decorators';

import LocationAndTimeStep from './LocationAndTimeStep';
import {
mockAppointmentDatesGet,
mockAppointmentLocationsGet,
mockAppointmentProductsGet,
mockAppointmentTimesGet,
} from './mocks';
import {withAppointmentState} from './story-utils';
} from '../mocks';
import {withAppointmentState} from '../story-utils';
import LocationAndTimeStep from './LocationAndTimeStep';

export default {
title: 'Private API / Appointments / Steps / 2 - Location and time',
Expand Down
3 changes: 3 additions & 0 deletions src/components/appointments/steps/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {default as ChooseProductStep} from './ChooseProductStep';
export {default as ContactDetailsStep} from './ContactDetailsStep';
export {default as LocationAndTimeStep} from './LocationAndTimeStep';

0 comments on commit 1f47894

Please sign in to comment.