Skip to content

Commit

Permalink
Fixes #894: Move constants to utility file and cleanup imports
Browse files Browse the repository at this point in the history
  • Loading branch information
zner0L committed May 31, 2022
1 parent 1a3a9fc commit 770f8f9
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/Components/Generator/CompanySelector.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Company } from '../../types/company';
import type { Except } from 'type-fest';
import t from '../../Utility/i18n';
import { useGeneratorStore } from '../../store/generator';
import { SearchBarProps, SearchBar } from '../SearchBar';
import type { Except } from 'type-fest';
import { useNewRequestModal } from './NewRequestButton';
import { Company } from '../../types/company.d';

type CompanySelectorProps = { newRequestHook: () => void } & Partial<Except<SearchBarProps, 'anchorize' | 'index'>>;

Expand Down
3 changes: 2 additions & 1 deletion src/Components/Generator/CustomRequestInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { CustomTemplateName } from '../../types/request';
import { MarkupText, Text, IntlProvider } from 'preact-i18n';
import t from '../../Utility/i18n';
import { useGeneratorStore } from '../../store/generator';
import { CUSTOM_TEMPLATE_OPTIONS, CustomTemplateName, EMTPY_ADDRESS } from '../../types/request.d';
import { EMTPY_ADDRESS, CUSTOM_TEMPLATE_OPTIONS } from '../../Utility/requests';
import { InputControl } from './DynamicInput';

export const CustomRequestInput = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Generator/DynamicInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { JSX } from 'preact';
import type { Address, AddressIdData, IdDataElement } from '../../types/request';
import { Text, IntlProvider } from 'preact-i18n';
import t from '../../Utility/i18n';
import { Address, AddressIdData, ADDRESS_STRING_PROPERTIES, IdDataElement } from '../../types/request.d';
import { ADDRESS_STRING_PROPERTIES } from '../../Utility/requests';
import { produce } from 'immer';

type DynamicInputProps = {
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Generator/DynamicInputContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ComponentChildren } from 'preact';
import type { IdDataElement } from '../../types/request';
import { useMemo, useState } from 'preact/hooks';
import { DynamicInput } from './DynamicInput';
import { Text, MarkupText, IntlProvider } from 'preact-i18n';
import t from '../../Utility/i18n';
import { EMTPY_ADDRESS, IdDataElement } from '../../types/request.d';
import { adressesEqual, isFieldEmpty } from '../../Utility/requests';
import { adressesEqual, isFieldEmpty, EMTPY_ADDRESS } from '../../Utility/requests';
import { useGeneratorStore } from '../../store/generator';

type DynamicInputContainerProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Generator/RecipientInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TransportMedium } from '../../types/request';
import t from '../../Utility/i18n';
import { Text, IntlProvider } from 'preact-i18n';
import { TransportMedium } from '../../types/request.d';

type RecipientInputProps = {
recipientAddress?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Generator/RequestTypeChooser.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { RequestType } from '../../types/request';
import t from '../../Utility/i18n';
import { Radio } from '../Radio';
import { RequestType, REQUEST_TYPES } from '../../types/request.d';
import { REQUEST_TYPES } from '../../Utility/requests';
import { useGeneratorStore } from '../../store/generator';

type RequestTypeChooserProps = {
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Generator/TransportMediumChooser.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { TransportMedium } from '../../types/request';
import t from '../../Utility/i18n';
import { Text, IntlProvider } from 'preact-i18n';
import { Radio } from '../Radio';
import { TransportMedium, TRANSPORT_MEDIA } from '../../types/request.d';
import { TRANSPORT_MEDIA } from '../../Utility/requests';

type TransportMediumChooserProps = {
value: TransportMedium;
Expand Down
6 changes: 3 additions & 3 deletions src/Components/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { MergeExclusive } from 'type-fest';
import type { SearchParams, SearchResponseHit } from 'typesense/lib/Typesense/Documents';
import type { Company } from '../types/company';
import { useEffect, useRef } from 'preact/hooks';
import { IntlProvider, MarkupText } from 'preact-i18n';
import { useAppStore, Country } from '../store/app';
Expand All @@ -6,9 +9,6 @@ import { Privacy, PRIVACY_ACTIONS } from '../Utility/Privacy';
import { searchClient } from '../Utility/search';
import { rethrow } from '../Utility/errors';
import { FeatureDisabledWidget } from './FeatureDisabledWidget';
import type { MergeExclusive } from 'type-fest';
import type { SearchParams, SearchResponseHit } from 'typesense/lib/Typesense/Documents';
import { Company } from '../types/company.d';

export type SearchBarProps = {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SvaFinder.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { SupervisoryAuthority } from '../types/company';
import { render, Fragment, JSX } from 'preact';
import { useState } from 'preact/hooks';
import { useAppStore } from '../store/app';
import t from '../Utility/i18n';
import { fetchSvaDataBySlug } from '../Utility/companies';
import deepmerge from 'deepmerge';
import { SupervisoryAuthority } from '../types/company.d';

type SvaFinderProps = {
callback?: (sva?: SupervisoryAuthority) => void;
Expand Down
6 changes: 3 additions & 3 deletions src/DataType/SavedIdData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { IdDataElement, Signature } from '../types/request';
import type { SetOptional } from 'type-fest';
import { rethrow, WarningException } from '../Utility/errors';
import Cookie from 'js-cookie';
import LocalForage from 'localforage';
import { EMTPY_ADDRESS, IdDataElement, Signature } from '../types/request.d';
import { produce, nothing } from 'immer';
import type { SetOptional } from 'type-fest';
import { isAddress } from '../Utility/requests';
import { isAddress, EMTPY_ADDRESS } from '../Utility/requests';

export class SavedIdData {
localforage_instance: LocalForage;
Expand Down
22 changes: 16 additions & 6 deletions src/Utility/requests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import t, { t_r } from './i18n';
import { CriticalException, rethrow } from './errors';
import { generateReference } from 'letter-generator';
import { deepCopyObject } from '../Utility/common';
import type {
IdDataElement,
Address,
Expand All @@ -12,9 +8,23 @@ import type {
CustomTemplateName,
} from '../types/request';
import type { Company, RequestLanguage, SupervisoryAuthority } from '../types/company';
import t, { t_r } from './i18n';
import { CriticalException, rethrow } from './errors';
import { generateReference } from 'letter-generator';
import { deepCopyObject } from '../Utility/common';

export const REQUEST_ARTICLES = { access: '15', erasure: '17', rectification: '16', objection: '21(2)' };
export const REQUEST_FALLBACK_LANGUAGE = 'en'; // We'll use English as hardcoded fallback language
export const REQUEST_TYPES = ['access', 'erasure', 'rectification', 'objection', 'custom'] as const;
export const TRANSPORT_MEDIA = ['email', 'letter', 'fax'] as const;
export const ADDRESS_STRING_PROPERTIES = ['street_1', 'street_2', 'place', 'country'] as const;
export const CUSTOM_TEMPLATE_OPTIONS = ['no-template', 'admonition', 'complaint'] as const;
export const REQUEST_ARTICLES = { access: '15', erasure: '17', rectification: '16', objection: '21(2)' } as const;
export const REQUEST_FALLBACK_LANGUAGE = 'en' as const; // We'll use English as hardcoded fallback language
export const EMTPY_ADDRESS: Address = {
street_1: '',
street_2: '',
place: '',
country: '',
} as const;

export function isAddress(value: IdDataElement['value']): value is Address {
return typeof value === 'object' && 'country' in value;
Expand Down
5 changes: 3 additions & 2 deletions src/store/generator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { IdDataElement, Request, ResponseType, Signature } from '../types/request';
import type { StoreSlice } from '../types/utility';
import create, { GetState, SetState } from 'zustand';
import { RequestState, createRequestStore } from './request';
import { CUSTOM_TEMPLATE_OPTIONS, IdDataElement, Request, ResponseType, Signature } from '../types/request.d';
import { CUSTOM_TEMPLATE_OPTIONS } from '../Utility/requests';
import createContext from 'zustand/context';
import { CompanyState, createCompanyStore } from './company';
import type { StoreSlice } from '../types/utility';
import { Privacy, PRIVACY_ACTIONS } from '../Utility/Privacy';
import { SavedIdData } from '../DataType/SavedIdData';
// This will be replaced with an URL by the worker-loader plugin in webpack which is why eslint can't find a default import (TS can be tricked by defining a module).
Expand Down
14 changes: 1 addition & 13 deletions src/types/request.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { RequestLanguage } from './company';

export const REQUEST_TYPES = ['access', 'erasure', 'rectification', 'objection', 'custom'] as const;
export const TRANSPORT_MEDIA = ['email', 'letter', 'fax'] as const;
import { REQUEST_TYPES, TRANSPORT_MEDIA, CUSTOM_TEMPLATE_OPTIONS } from '../Utility/requests';

export type RequestType = typeof REQUEST_TYPES[number];
export type TransportMedium = typeof TRANSPORT_MEDIA[number];
Expand Down Expand Up @@ -32,13 +30,6 @@ export interface AddressIdData extends GeneralIdData {
value: Address;
}

export const EMTPY_ADDRESS: Address = {
street_1: '',
street_2: '',
place: '',
country: '',
} as const;

export type IdDataElement = TextIdData | AddressIdData;
export type ResponseType = 'admonition' | 'complaint';

Expand All @@ -54,8 +45,6 @@ export type ImageSignature = {
};
export type Signature = TextSignature | ImageSignature;

export const ADDRESS_STRING_PROPERTIES = ['street_1', 'street_2', 'place', 'country'] as const;

export type Address = {
street_1: string;
street_2: string;
Expand Down Expand Up @@ -114,7 +103,6 @@ export interface CustomRequest extends RequestInterface {
response_type?: ResponseType;
}

export const CUSTOM_TEMPLATE_OPTIONS = ['no-template', 'admonition', 'complaint'] as const;
type CustomTemplateName = typeof CUSTOM_TEMPLATE_OPTIONS[number];

export interface ObjectionRequest extends RequestInterface {
Expand Down

0 comments on commit 770f8f9

Please sign in to comment.