likyh commented on code in PR #4948:
URL:
https://github.com/apache/incubator-devlake/pull/4948#discussion_r1172670721
##########
config-ui/src/plugins/register/jira/connection-fields/auth.tsx:
##########
@@ -25,109 +25,185 @@ import * as S from './styled';
type Method = 'BasicAuth' | 'AccessToken';
-type Value = {
- authMethod: Method;
- username: string;
- password: string;
- token: string;
-};
-
interface Props {
- initialValue: Value;
- value: Value;
- error: string;
- setValue: (value: Value) => void;
- setError: (value: string) => void;
+ initialValues: any;
+ values: any;
+ errors: any;
+ setValues: (value: any) => void;
+ setErrors: (value: any) => void;
}
-export const Auth = ({ initialValue, value, error, setValue, setError }:
Props) => {
+export const Auth = ({ initialValues, values, errors, setValues, setErrors }:
Props) => {
+ const [version, setVersion] = useState('cloud');
+
useEffect(() => {
- setValue(initialValue);
- }, [initialValue]);
+ setValues({
+ endpoint: initialValues.endpoint,
+ authMethod: initialValues.authMethod ?? 'BasicAuth',
+ username: initialValues.username,
+ password: initialValues.password,
+ token: initialValues.token,
+ });
+ }, [
+ initialValues.endpoint,
+ initialValues.authMethod,
+ initialValues.username,
+ initialValues.password,
+ initialValues.token,
+ ]);
useEffect(() => {
const required =
- (value.authMethod === 'BasicAuth' && value.username && value.password) ||
- (value.authMethod === 'AccessToken' && value.token);
- setError(required ? '' : 'auth is required');
- }, [value]);
+ (values.authMethod === 'BasicAuth' && values.username &&
values.password) ||
+ (values.authMethod === 'AccessToken' && values.token);
+ setErrors({
+ endpoint: !values.endpoint ? 'endpoint is required' : '',
+ auth: required ? '' : 'auth is required',
+ });
+ }, [values]);
+
+ const handleChangeVersion = (e: React.FormEvent<HTMLInputElement>) => {
+ const version = (e.target as HTMLInputElement).value;
+
+ setValues({
+ endpoint: '',
+ authMethod: 'BasicAuth',
+ username: undefined,
+ password: undefined,
+ token: undefined,
+ });
+
+ setVersion(version);
+ };
+
+ const handleChangeEndpoint = (e: React.ChangeEvent<HTMLInputElement>) => {
+ setValues({
+ endpoint: e.target.value,
+ });
+ };
const handleChangeMethod = (e: React.FormEvent<HTMLInputElement>) => {
- setValue({
- ...value,
+ setValues({
authMethod: (e.target as HTMLInputElement).value as Method,
+ username: undefined,
+ password: undefined,
+ token: undefined,
});
};
const handleChangeUsername = (e: React.ChangeEvent<HTMLInputElement>) => {
- setValue({
- ...value,
+ setValues({
username: e.target.value,
});
};
const handleChangePassword = (e: React.ChangeEvent<HTMLInputElement>) => {
- setValue({
- ...value,
+ setValues({
password: e.target.value,
});
};
const handleChangeToken = (e: React.ChangeEvent<HTMLInputElement>) => {
- setValue({
- ...value,
+ setValues({
token: e.target.value,
});
};
+ console.log(errors);
Review Comment:
delete debug code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]