mirror of
https://github.com/Radarr/Radarr
synced 2026-01-19 05:53:51 +01:00
Co-authored-by: Mark McDowall <mark@mcdowall.ca> Remove defaultProps from TypeScript components (cherry picked from commit a90c13e86f798841cb6db038bb6b6d1408a00585) Fix multi-select checkboxes not appearing (cherry picked from commit e199710c15fbfa643a9f71c7a20f70b1722d0df6)
72 lines
1.5 KiB
TypeScript
72 lines
1.5 KiB
TypeScript
import React, { useCallback, useEffect } from 'react';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import AppState from 'App/State/AppState';
|
|
import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton';
|
|
import { kinds } from 'Helpers/Props';
|
|
import { resetOAuth, startOAuth } from 'Store/Actions/oAuthActions';
|
|
import { InputOnChange } from 'typings/inputs';
|
|
|
|
interface OAuthInputProps {
|
|
label?: string;
|
|
name: string;
|
|
provider: string;
|
|
providerData: object;
|
|
section: string;
|
|
onChange: InputOnChange<unknown>;
|
|
}
|
|
|
|
function OAuthInput({
|
|
label = 'Start OAuth',
|
|
name,
|
|
provider,
|
|
providerData,
|
|
section,
|
|
onChange,
|
|
}: OAuthInputProps) {
|
|
const dispatch = useDispatch();
|
|
const { authorizing, error, result } = useSelector(
|
|
(state: AppState) => state.oAuth
|
|
);
|
|
|
|
const handlePress = useCallback(() => {
|
|
dispatch(
|
|
startOAuth({
|
|
name,
|
|
provider,
|
|
providerData,
|
|
section,
|
|
})
|
|
);
|
|
}, [name, provider, providerData, section, dispatch]);
|
|
|
|
useEffect(() => {
|
|
if (!result) {
|
|
return;
|
|
}
|
|
|
|
Object.keys(result).forEach((key) => {
|
|
onChange({ name: key, value: result[key] });
|
|
});
|
|
}, [result, onChange]);
|
|
|
|
useEffect(() => {
|
|
return () => {
|
|
dispatch(resetOAuth());
|
|
};
|
|
}, [dispatch]);
|
|
|
|
return (
|
|
<div>
|
|
<SpinnerErrorButton
|
|
kind={kinds.PRIMARY}
|
|
isSpinning={authorizing}
|
|
error={error}
|
|
onPress={handlePress}
|
|
>
|
|
{label}
|
|
</SpinnerErrorButton>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default OAuthInput;
|