initial commit for welsh government planning appeals application
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
import _ from "lodash";
|
||||
import React, { useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import {
|
||||
Field,
|
||||
reduxForm,
|
||||
formValueSelector,
|
||||
getFormSubmitErrors,
|
||||
} from "redux-form";
|
||||
import { useDispatch, useSelector, shallowEqual, connect } from "react-redux";
|
||||
import {
|
||||
Textfield,
|
||||
DateField,
|
||||
DateFieldPicker,
|
||||
YesNofield,
|
||||
PickList,
|
||||
MultiLinefield,
|
||||
NumericField,
|
||||
ReadOnlyfield,
|
||||
DecimalField,
|
||||
} from "../elements";
|
||||
|
||||
const RenderTextfield = ({
|
||||
id,
|
||||
className,
|
||||
rows,
|
||||
datafieldname,
|
||||
name,
|
||||
label,
|
||||
input,
|
||||
type,
|
||||
errorMsg,
|
||||
meta: { touched, error },
|
||||
...custom
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={
|
||||
touched && error
|
||||
? "govuk-form-group govuk-form-group--error"
|
||||
: "govuk-form-group "
|
||||
}
|
||||
>
|
||||
<label className="govuk-label " htmlFor={id} id={id + "_label"}>
|
||||
{label}
|
||||
</label>
|
||||
{touched && error && (
|
||||
<span id={id + "-error"} className="govuk-error-message">
|
||||
<span className="govuk-visually-hidden">Error:</span>{" "}
|
||||
{touched &&
|
||||
((error && (
|
||||
<span>{errorMsg ? errorMsg : error}</span>
|
||||
)) ||
|
||||
(warning && <span>{warning}</span>))}
|
||||
</span>
|
||||
)}
|
||||
<input
|
||||
{...input}
|
||||
className={className}
|
||||
name={name}
|
||||
id={id}
|
||||
type={type}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const ChangePassword = (props) => {
|
||||
const { footerLinks, pages, handleSubmit, value } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
let errorsobj = {};
|
||||
|
||||
const onHandleSubmit = (values) => {
|
||||
console.log(values);
|
||||
};
|
||||
|
||||
const required = (value) => (value ? undefined : "Is required");
|
||||
|
||||
const matchInput = (input, allInputs) => {
|
||||
return input === allInputs.password
|
||||
? undefined
|
||||
: "Passwords do not match";
|
||||
};
|
||||
|
||||
const email = (value) =>
|
||||
value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value)
|
||||
? "Invalid email address"
|
||||
: undefined;
|
||||
const phoneNumber = (value) =>
|
||||
value &&
|
||||
!/^(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?(?:\(?0\)?[\s-]?)?)|(?:\(?0))(?:(?:\d{5}\)?[\s-]?\d{4,5})|(?:\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3}))|(?:\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4})|(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}))(?:[\s-]?(?:x|ext\.?|\#)\d{3,4})?$/i.test(
|
||||
value
|
||||
)
|
||||
? "Invalid phone number"
|
||||
: undefined;
|
||||
|
||||
const [hasErrors, setHasErrors] = useState("");
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* {hasErrors == true ? (
|
||||
<ShowErrorHeader
|
||||
hasErrors={hasErrors}
|
||||
props={props.props.form}
|
||||
formXML={formXML}
|
||||
/>
|
||||
) : (
|
||||
""
|
||||
)} */}
|
||||
<form onSubmit={handleSubmit(onHandleSubmit)}>
|
||||
<fieldset className="govuk-fieldset">
|
||||
<Field
|
||||
name="newpassword"
|
||||
id="newpassword"
|
||||
component={RenderTextfield}
|
||||
type="password"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
validate={[required]}
|
||||
label="New password"
|
||||
/>
|
||||
<Field
|
||||
name="confirmpassword"
|
||||
id="confirmpassword"
|
||||
component={RenderTextfield}
|
||||
type="password"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
validate={[matchInput]}
|
||||
label="Confirm new password"
|
||||
/>
|
||||
</fieldset>
|
||||
|
||||
<div className="govuk-button-group">
|
||||
<button
|
||||
type="submit"
|
||||
className="govuk-button"
|
||||
data-module="govuk-button"
|
||||
>
|
||||
Continue
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
search: state.search,
|
||||
searchResultsObj: state.searchResultsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
//form: state.form,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
setCurrentSection: (currentSection) => {
|
||||
dispatch(setCurrentSection(currentSection));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const selector = formValueSelector("changepasswordForm"); // <-- same as form name
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(
|
||||
reduxForm({
|
||||
form: "changepasswordForm",
|
||||
destroyOnUnmount: false,
|
||||
})(ChangePassword)
|
||||
);
|
||||
Reference in New Issue
Block a user