diff --git a/app/javascript/components/TypesDeChampEditor/Flash.js b/app/javascript/components/TypesDeChampEditor/Flash.ts similarity index 61% rename from app/javascript/components/TypesDeChampEditor/Flash.js rename to app/javascript/components/TypesDeChampEditor/Flash.ts index 945c6efd8..302c88c9f 100644 --- a/app/javascript/components/TypesDeChampEditor/Flash.js +++ b/app/javascript/components/TypesDeChampEditor/Flash.ts @@ -1,6 +1,14 @@ -export default class Flash { - constructor(isAnnotation) { - this.element = document.querySelector('#flash_messages'); +import invariant from 'tiny-invariant'; + +export class Flash { + element: HTMLDivElement; + isAnnotation: boolean; + timeout?: number; + + constructor(isAnnotation: boolean) { + const element = document.querySelector('#flash_messages'); + invariant(element, 'Flash element is required'); + this.element = element; this.isAnnotation = isAnnotation; } success() { @@ -10,13 +18,13 @@ export default class Flash { this.add('Formulaire enregistré.'); } } - error(message) { + error(message: string) { this.add(message, true); } clear() { this.element.innerHTML = ''; } - add(message, isError) { + add(message: string, isError = false) { const html = `
@@ -20,10 +27,3 @@ function DescriptionInput({ isVisible, handler }) { } return null; } - -DescriptionInput.propTypes = { - isVisible: PropTypes.bool, - handler: PropTypes.object -}; - -export default DescriptionInput; diff --git a/app/javascript/components/TypesDeChampEditor/components/LibelleInput.jsx b/app/javascript/components/TypesDeChampEditor/components/LibelleInput.tsx similarity index 66% rename from app/javascript/components/TypesDeChampEditor/components/LibelleInput.jsx rename to app/javascript/components/TypesDeChampEditor/components/LibelleInput.tsx index f1ca7c07c..c7490cec6 100644 --- a/app/javascript/components/TypesDeChampEditor/components/LibelleInput.jsx +++ b/app/javascript/components/TypesDeChampEditor/components/LibelleInput.tsx @@ -1,7 +1,14 @@ import React from 'react'; -import PropTypes from 'prop-types'; -function LibelleInput({ isVisible, handler }) { +import type { Handler } from '../types'; + +export function LibelleInput({ + isVisible, + handler +}: { + isVisible: boolean; + handler: Handler; +}) { if (isVisible) { return (
@@ -19,10 +26,3 @@ function LibelleInput({ isVisible, handler }) { } return null; } - -LibelleInput.propTypes = { - handler: PropTypes.object, - isVisible: PropTypes.bool -}; - -export default LibelleInput; diff --git a/app/javascript/components/TypesDeChampEditor/components/MandatoryInput.jsx b/app/javascript/components/TypesDeChampEditor/components/MandatoryInput.tsx similarity index 66% rename from app/javascript/components/TypesDeChampEditor/components/MandatoryInput.jsx rename to app/javascript/components/TypesDeChampEditor/components/MandatoryInput.tsx index 436a23345..9a13cc161 100644 --- a/app/javascript/components/TypesDeChampEditor/components/MandatoryInput.jsx +++ b/app/javascript/components/TypesDeChampEditor/components/MandatoryInput.tsx @@ -1,7 +1,14 @@ import React from 'react'; -import PropTypes from 'prop-types'; -function MandatoryInput({ isVisible, handler }) { +import type { Handler } from '../types'; + +export function MandatoryInput({ + isVisible, + handler +}: { + isVisible: boolean; + handler: Handler; +}) { if (isVisible) { return (
@@ -19,10 +26,3 @@ function MandatoryInput({ isVisible, handler }) { } return null; } - -MandatoryInput.propTypes = { - handler: PropTypes.object, - isVisible: PropTypes.bool -}; - -export default MandatoryInput; diff --git a/app/javascript/components/TypesDeChampEditor/components/MoveButton.jsx b/app/javascript/components/TypesDeChampEditor/components/MoveButton.tsx similarity index 56% rename from app/javascript/components/TypesDeChampEditor/components/MoveButton.jsx rename to app/javascript/components/TypesDeChampEditor/components/MoveButton.tsx index c8ec442f9..15796767a 100644 --- a/app/javascript/components/TypesDeChampEditor/components/MoveButton.jsx +++ b/app/javascript/components/TypesDeChampEditor/components/MoveButton.tsx @@ -1,8 +1,17 @@ -import React from 'react'; -import PropTypes from 'prop-types'; +import React, { MouseEventHandler } from 'react'; import { ArrowDownIcon, ArrowUpIcon } from '@heroicons/react/solid'; -function MoveButton({ isEnabled, icon, title, onClick }) { +export function MoveButton({ + isEnabled, + icon, + title, + onClick +}: { + isEnabled: boolean; + icon: string; + title: string; + onClick: MouseEventHandler; +}) { return (