import React, { useCallback, useState } from 'react'; import FormGroup from 'Components/Form/FormGroup'; import FormInputGroup from 'Components/Form/FormInputGroup'; import FormLabel from 'Components/Form/FormLabel'; import Button from 'Components/Link/Button'; import ModalBody from 'Components/Modal/ModalBody'; import ModalContent from 'Components/Modal/ModalContent'; import ModalFooter from 'Components/Modal/ModalFooter'; import ModalHeader from 'Components/Modal/ModalHeader'; import { inputTypes } from 'Helpers/Props'; import MoveMovieModal from 'Movie/MoveMovie/MoveMovieModal'; import translate from 'Utilities/String/translate'; import styles from './EditMoviesModalContent.css'; interface SavePayload { monitored?: boolean; qualityProfileId?: number; rootFolderPath?: string; moveFiles?: boolean; } interface EditMoviesModalContentProps { movieIds: number[]; onSavePress(payload: object): void; onModalClose(): void; } const NO_CHANGE = 'noChange'; const monitoredOptions = [ { key: NO_CHANGE, value: 'No Change', disabled: true }, { key: 'monitored', value: 'Monitored' }, { key: 'unmonitored', value: 'Unmonitored' }, ]; function EditMoviesModalContent(props: EditMoviesModalContentProps) { const { movieIds, onSavePress, onModalClose } = props; const [monitored, setMonitored] = useState(NO_CHANGE); const [qualityProfileId, setQualityProfileId] = useState( NO_CHANGE ); const [rootFolderPath, setRootFolderPath] = useState(NO_CHANGE); const [isConfirmMoveModalOpen, setIsConfirmMoveModalOpen] = useState(false); const save = useCallback( (moveFiles) => { let hasChanges = false; const payload: SavePayload = {}; if (monitored !== NO_CHANGE) { hasChanges = true; payload.monitored = monitored === 'monitored'; } if (qualityProfileId !== NO_CHANGE) { hasChanges = true; payload.qualityProfileId = qualityProfileId as number; } if (rootFolderPath !== NO_CHANGE) { hasChanges = true; payload.rootFolderPath = rootFolderPath; payload.moveFiles = moveFiles; } if (hasChanges) { onSavePress(payload); } onModalClose(); }, [monitored, qualityProfileId, rootFolderPath, onSavePress, onModalClose] ); const onInputChange = useCallback( ({ name, value }) => { switch (name) { case 'monitored': setMonitored(value); break; case 'qualityProfileId': setQualityProfileId(value); break; case 'rootFolderPath': setRootFolderPath(value); break; default: console.warn('EditMoviesModalContent Unknown Input'); } }, [setMonitored] ); const onSavePressWrapper = useCallback(() => { if (rootFolderPath === NO_CHANGE) { save(false); } else { setIsConfirmMoveModalOpen(true); } }, [rootFolderPath, save]); const onCancelPress = useCallback(() => { setIsConfirmMoveModalOpen(false); }, [setIsConfirmMoveModalOpen]); const onDoNotMoveMoviePress = useCallback(() => { setIsConfirmMoveModalOpen(false); save(false); }, [setIsConfirmMoveModalOpen, save]); const onMoveMoviePress = useCallback(() => { setIsConfirmMoveModalOpen(false); save(true); }, [setIsConfirmMoveModalOpen, save]); const selectedCount = movieIds.length; return ( {translate('EditSelectedMovies')} {translate('Monitored')} {translate('Quality Profile')} {translate('Root Folder')}
{translate('MoviesSelectedInterp', selectedCount.toString())}
); } export default EditMoviesModalContent;