From 54a50590801ead63b3e20a4dd272aa181ebe6481 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 22 Sep 2024 07:04:14 +0300 Subject: [PATCH] Convert AvailabilitySelectInput to TypeScript --- .../Form/AvailabilitySelectInput.js | 69 ------------------- .../Form/AvailabilitySelectInput.tsx | 67 ++++++++++++++++++ 2 files changed, 67 insertions(+), 69 deletions(-) delete mode 100644 frontend/src/Components/Form/AvailabilitySelectInput.js create mode 100644 frontend/src/Components/Form/AvailabilitySelectInput.tsx diff --git a/frontend/src/Components/Form/AvailabilitySelectInput.js b/frontend/src/Components/Form/AvailabilitySelectInput.js deleted file mode 100644 index 4b65ea1db..000000000 --- a/frontend/src/Components/Form/AvailabilitySelectInput.js +++ /dev/null @@ -1,69 +0,0 @@ -import PropTypes from 'prop-types'; -import React from 'react'; -import translate from 'Utilities/String/translate'; -import EnhancedSelectInput from './EnhancedSelectInput'; - -const availabilityOptions = [ - { - key: 'announced', - get value() { - return translate('Announced'); - } - }, - { - key: 'inCinemas', - get value() { - return translate('InCinemas'); - } - }, - { - key: 'released', - get value() { - return translate('Released'); - } - } -]; - -function AvailabilitySelectInput(props) { - const values = [...availabilityOptions]; - - const { - includeNoChange, - includeMixed - } = props; - - if (includeNoChange) { - values.unshift({ - key: 'noChange', - value: translate('NoChange'), - isDisabled: true - }); - } - - if (includeMixed) { - values.unshift({ - key: 'mixed', - value: '(Mixed)', - isDisabled: true - }); - } - - return ( - - ); -} - -AvailabilitySelectInput.propTypes = { - includeNoChange: PropTypes.bool.isRequired, - includeMixed: PropTypes.bool.isRequired -}; - -AvailabilitySelectInput.defaultProps = { - includeNoChange: false, - includeMixed: false -}; - -export default AvailabilitySelectInput; diff --git a/frontend/src/Components/Form/AvailabilitySelectInput.tsx b/frontend/src/Components/Form/AvailabilitySelectInput.tsx new file mode 100644 index 000000000..3e161d18d --- /dev/null +++ b/frontend/src/Components/Form/AvailabilitySelectInput.tsx @@ -0,0 +1,67 @@ +import React from 'react'; +import translate from 'Utilities/String/translate'; +import EnhancedSelectInput from './EnhancedSelectInput'; + +interface AvailabilitySelectInputProps { + includeNoChange: boolean; + includeNoChangeDisabled?: boolean; + includeMixed?: boolean; +} + +interface IMovieAvailabilityOption { + key: string; + value: string; + format?: string; + isDisabled?: boolean; +} + +const movieAvailabilityOptions: IMovieAvailabilityOption[] = [ + { + key: 'announced', + get value() { + return translate('Announced'); + }, + }, + { + key: 'inCinemas', + get value() { + return translate('InCinemas'); + }, + }, + { + key: 'released', + get value() { + return translate('Released'); + }, + }, +]; + +function AvailabilitySelectInput(props: AvailabilitySelectInputProps) { + const values = [...movieAvailabilityOptions]; + + const { + includeNoChange = false, + includeNoChangeDisabled = true, + includeMixed = false, + } = props; + + if (includeNoChange) { + values.unshift({ + key: 'noChange', + value: translate('NoChange'), + isDisabled: includeNoChangeDisabled, + }); + } + + if (includeMixed) { + values.unshift({ + key: 'mixed', + value: `(${translate('Mixed')})`, + isDisabled: true, + }); + } + + return ; +} + +export default AvailabilitySelectInput;