Skip to content

Commit

Permalink
Fix various components types
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Eric Garcia committed Aug 11, 2023
1 parent 2565101 commit c30a8ce
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 34 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/atoms/inputs/FieldsetWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './FieldsetWrapper.css';

type FieldsetWrapperProps = {
title?: string;
title?: string | React.ReactNode;
required?: boolean;
grid?: boolean;
inline?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/atoms/inputs/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Label from './Label';
export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
label?: string;
helper?: string;
meta?: string;
meta?: string | React.ReactNode;
ariaLabel?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/atoms/inputs/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Props = {
label: ReactNode;
required?: boolean;
helper?: string;
meta?: string;
meta?: string | React.ReactNode;
};

export const Label: FunctionComponent<Props> = ({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/molecules/ListHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './style.css';

type Props = {
title: string;
children: React.ReactNode;
children?: React.ReactNode;
};

export const ListHeader: React.FC<Props> = ({ title, children = null }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import NumberInput from '../../atoms/inputs/NumberInput';
import './style.css';
import { Table } from '@tanstack/react-table';

const TablePagination = ({ table }: { table: Table<any> }) => {
const TablePagination = ({ table }: { table: Table<unknown> }) => {
return (
<div className="table-pagination-container page-container">
<Button
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/organisms/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent } from 'react';
import React from 'react';
import httpClient from '../../lib/http-client';
import { getErrorMessages } from '../../lib';
import { Login } from '../templates/Login';
Expand Down Expand Up @@ -64,7 +64,7 @@ export const useAuth = () => {
*/
export let resetAuthContext = (): void => {};

export class AuthStore extends React.Component {
export class AuthStore extends React.Component<{ children: React.ReactNode }> {
_isMounted: boolean;
state: {
user: any;
Expand Down Expand Up @@ -147,7 +147,11 @@ export class AuthStore extends React.Component {
}
}

export const AuthRequired: FunctionComponent = ({ children }) => {
type AuthRequiredProps = {
children: React.ReactNode;
};

export const AuthRequired: React.FC<AuthRequiredProps> = ({ children }) => {
const { user } = useAuth();

if (!user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ const InstructorEnrollmentListFilters = ({
<Label id="target_api" label="Filtrer par API" />
<MultiSelect
id="target_api"
options={user?.roles
.filter((role) => role.endsWith(':reporter'))
.map((role) => {
const targetApiKey = role.split(':')[0];
options={
user?.roles
.filter((role) => role.endsWith(':reporter'))
.map((role) => {
const targetApiKey = role.split(':')[0];

return {
key: targetApiKey,
label: dataProviderConfigurations?.[targetApiKey].label,
};
})}
return {
key: targetApiKey,
label: dataProviderConfigurations?.[targetApiKey]
.label as string,
};
}) || []
}
values={
filters.find(({ id }: { id: string }) => id === 'target_api')?.value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const HideSectionsContext = createContext<HideSectionsContextType>({
setLastIndexToShow: () => null,
});

export const HideSectionsContainer: FunctionComponent = ({ children }) => {
export const HideSectionsContainer: FunctionComponent<{
children: React.ReactNode | React.ReactNode[];
}> = ({ children }) => {
const [showOnlyFirstStep, setShowOnlyFirstStep] = useState(false);
const [isShowNextStepButtonDisabled, setIsShowNextStepButtonDisabled] =
useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ describe('The form submission hook', () => {
const updateEnrollment = jest.fn();
const processEvent = jest.fn();

const wrapper: FunctionComponent = ({ children }) => (
const wrapper: FunctionComponent<{ children: React.ReactNode }> = ({
children,
}) => (
<OpenMessagePromptContext.Provider
value={{
onClick: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useContext, useEffect, useState } from 'react';
import {
EnrollmentEvent,
EventConfiguration,
eventConfigurations,
PromptType,
} from '../../../../../config/event-configuration';
Expand All @@ -22,7 +23,9 @@ export const useFormSubmission = (
async (event: EnrollmentEvent) => {
setPendingEvent(event);

const eventConfiguration = eventConfigurations[event];
const eventConfiguration = eventConfigurations[
event
] as EventConfiguration;
if (!eventConfiguration.prompt) {
setLoading(true);
setPendingEvent(undefined);
Expand Down Expand Up @@ -62,20 +65,20 @@ export const useFormSubmission = (

const eventToProcess =
pendingEvent &&
eventConfigurations[pendingEvent].prompt === PromptType.submit_instead
eventConfigurations[pendingEvent]?.prompt === PromptType.submit_instead
? EnrollmentEvent.submit
: pendingEvent;

const onPromptConfirmation = pendingEvent
? onPromptConfirmationFactory(
eventConfigurations[pendingEvent].prompt === PromptType.submit_instead
eventConfigurations[pendingEvent]?.prompt === PromptType.submit_instead
? EnrollmentEvent.submit
: eventToProcess!
)
: () => null;

const onPromptCancellation = pendingEvent
? eventConfigurations[pendingEvent].prompt === PromptType.submit_instead
? eventConfigurations[pendingEvent]?.prompt === PromptType.submit_instead
? onPromptConfirmationFactory(pendingEvent)
: () => {
setPendingEvent(undefined);
Expand Down
26 changes: 18 additions & 8 deletions frontend/src/components/templates/Form/SubmissionPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FunctionComponent, useState } from 'react';
import { FunctionComponent, MouseEventHandler, useState } from 'react';
import {
EventConfiguration,
eventConfigurations,
PromptType,
} from '../../../../config/event-configuration';
Expand Down Expand Up @@ -51,19 +52,26 @@ const SubmissionPanel: FunctionComponent<Props> = ({
{loading && <Loader enableBePatientMessage />}

{pendingEvent &&
eventConfigurations[pendingEvent].prompt === PromptType.comment && (
eventConfigurations[pendingEvent] &&
eventConfigurations[pendingEvent]?.prompt === PromptType.comment && (
<Prompt
inputValue={promptInputValue}
setInputValue={setPromptInputValue}
onAccept={onPromptConfirmation}
onCancel={onPromptCancellation}
displayProps={eventConfigurations[pendingEvent!].displayProps}
selectedEvent={pendingEvent as string}
onCancel={
onPromptCancellation as MouseEventHandler<HTMLButtonElement>
}
displayProps={
eventConfigurations[pendingEvent!]
?.displayProps as EventConfiguration['displayProps']
}
selectedEvent={pendingEvent}
enrollment={enrollment}
/>
)}
{pendingEvent &&
eventConfigurations[pendingEvent].prompt ===
eventConfigurations[pendingEvent] &&
eventConfigurations[pendingEvent]?.prompt ===
PromptType.submit_instead && (
<ConfirmationModal
title="Vos modifications vont être enregistrées."
Expand All @@ -79,7 +87,8 @@ const SubmissionPanel: FunctionComponent<Props> = ({
</ConfirmationModal>
)}
{pendingEvent &&
eventConfigurations[pendingEvent].prompt ===
eventConfigurations[pendingEvent] &&
eventConfigurations[pendingEvent]?.prompt ===
PromptType.confirm_deletion && (
<ConfirmationModal
title="La suppression d'une habilitation est irréversible"
Expand All @@ -90,7 +99,8 @@ const SubmissionPanel: FunctionComponent<Props> = ({
</ConfirmationModal>
)}
{pendingEvent &&
eventConfigurations[pendingEvent].prompt ===
eventConfigurations[pendingEvent] &&
eventConfigurations[pendingEvent]?.prompt ===
PromptType.confirm_archive && (
<ConfirmationModal
title="Vous n’aurez plus accès à cette habilitation"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import {
DATA_PROVIDER_CONFIGURATIONS,
FullDataProviderConfiguration,
TargetAPI,
} from '../../../config/data-provider-configurations';
import { useEffect, useState } from 'react';
import { getCachedDataProviderConfiguration } from '../../../services/data-provider-configurations';
import { AxiosError } from 'axios';

function getLocalConfiguration(targetApi: string) {
function getLocalConfiguration(targetApi: TargetAPI) {
return DATA_PROVIDER_CONFIGURATIONS[targetApi];
}

export const useFullDataProvider = ({ targetApi }: { targetApi: string }) => {
export const useFullDataProvider = ({
targetApi,
}: {
targetApi: TargetAPI;
}) => {
const [notFound, setNotFound] = useState<boolean>(false);
const [configuration, setConfiguration] =
useState<FullDataProviderConfiguration | null>(null);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/services/enrollments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ describe('getUserEnrollment', () => {
describe('serializeEnrollment', () => {
describe('When there is a response', () => {
it('should return a 200 status', () => {
const enrollment: Enrollment = FIRST_ENROLLMENT_1.enrollment;
const enrollment: Enrollment =
FIRST_ENROLLMENT_1.enrollment as Enrollment;

const formData = serializeEnrollment(enrollment);
expect(formData.getAll('enrollment[status]')).toEqual(['draft']);
Expand Down

0 comments on commit c30a8ce

Please sign in to comment.