mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 06:28:33 +00:00
90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
import React from 'react';
|
|
import SensitiveFieldWarning from 'components/SensitiveFieldWarning';
|
|
import { useDetectSensitiveField } from 'hooks/useDetectSensitiveField';
|
|
import get from 'lodash/get';
|
|
import { useTheme } from 'providers/Theme';
|
|
import { useDispatch } from 'react-redux';
|
|
import SingleLineEditor from 'components/SingleLineEditor';
|
|
import { updateAuth } from 'providers/ReduxStore/slices/collections';
|
|
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
const WsseAuth = ({ item, collection, updateAuth, request, save }) => {
|
|
const dispatch = useDispatch();
|
|
const { storedTheme } = useTheme();
|
|
|
|
const wsseAuth = get(request, 'auth.wsse', {});
|
|
const { isSensitive } = useDetectSensitiveField(collection);
|
|
const { showWarning, warningMessage } = isSensitive(wsseAuth?.password);
|
|
|
|
const handleRun = () => dispatch(sendRequest(item, collection.uid));
|
|
|
|
const handleSave = () => {
|
|
save();
|
|
};
|
|
|
|
const handleUserChange = (username) => {
|
|
dispatch(
|
|
updateAuth({
|
|
mode: 'wsse',
|
|
collectionUid: collection.uid,
|
|
itemUid: item.uid,
|
|
content: {
|
|
username: username || '',
|
|
password: wsseAuth.password || ''
|
|
}
|
|
})
|
|
);
|
|
};
|
|
|
|
const handlePasswordChange = (password) => {
|
|
dispatch(
|
|
updateAuth({
|
|
mode: 'wsse',
|
|
collectionUid: collection.uid,
|
|
itemUid: item.uid,
|
|
content: {
|
|
username: wsseAuth.username || '',
|
|
password: password || ''
|
|
}
|
|
})
|
|
);
|
|
};
|
|
|
|
return (
|
|
<StyledWrapper className="mt-2 w-full">
|
|
<label className="block mb-1">Username</label>
|
|
<div className="single-line-editor-wrapper mb-3">
|
|
<SingleLineEditor
|
|
value={wsseAuth.username || ''}
|
|
theme={storedTheme}
|
|
onSave={handleSave}
|
|
onChange={(val) => handleUserChange(val)}
|
|
onRun={handleRun}
|
|
collection={collection}
|
|
item={item}
|
|
isCompact
|
|
/>
|
|
</div>
|
|
|
|
<label className="block mb-1">Password</label>
|
|
<div className="single-line-editor-wrapper flex items-center">
|
|
<SingleLineEditor
|
|
value={wsseAuth.password || ''}
|
|
theme={storedTheme}
|
|
onSave={handleSave}
|
|
onChange={(val) => handlePasswordChange(val)}
|
|
onRun={handleRun}
|
|
collection={collection}
|
|
item={item}
|
|
isSecret={true}
|
|
isCompact
|
|
/>
|
|
{showWarning && <SensitiveFieldWarning fieldName="wsse-password" warningMessage={warningMessage} />}
|
|
</div>
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default WsseAuth;
|