Url configuration
This commit is contained in:
@@ -1,19 +1,19 @@
|
|||||||
import { Form, Formik } from "formik";
|
import {Form, Formik} from "formik";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import { useMutation } from '@tanstack/react-query';
|
import {useMutation} from '@tanstack/react-query';
|
||||||
import { setExternalURL } from '../../../services/services';
|
import {setExternalURL} from '../../../services/services';
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
url: Yup.string().required("URL is required").matches(/^https?:\/\/[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+\.[a-zA-Z]+/, 'Must be like: https://example.mysite.com'),
|
url: Yup.string().required("URL is required").matches(/^https?:\/\/[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+\.[a-zA-Z]+/, 'Must be like: https://example.mysite.com'),
|
||||||
})
|
})
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
url: '',
|
url: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const URLConfiguration = ({productData}) => {
|
const URLConfiguration = ({productData}) => {
|
||||||
|
|
||||||
let defaultUrl= 'https://'+productData?.internal_url
|
let defaultUrl = 'https://' + productData?.internal_url
|
||||||
|
|
||||||
// API to set url
|
// API to set url
|
||||||
const setURL = useMutation({
|
const setURL = useMutation({
|
||||||
@@ -21,13 +21,13 @@ const URLConfiguration = ({productData}) => {
|
|||||||
return setExternalURL(fields)
|
return setExternalURL(fields)
|
||||||
},
|
},
|
||||||
onSuccess: (res) => {
|
onSuccess: (res) => {
|
||||||
if(res.data.resultCode != '0'){
|
if (res.data.resultCode != '0') {
|
||||||
// throw({message: res?.data?.resultDescription})
|
// throw({message: res?.data?.resultDescription})
|
||||||
throw({message: 'Something went wrong!'})
|
throw({message: 'Something went wrong!'})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSettled: () => {
|
onSettled: () => {
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
setURL.reset()
|
setURL.reset()
|
||||||
}, 3000)
|
}, 3000)
|
||||||
}
|
}
|
||||||
@@ -50,17 +50,16 @@ const URLConfiguration = ({productData}) => {
|
|||||||
<div className="card card-statistics">
|
<div className="card card-statistics">
|
||||||
<div className="card-header">
|
<div className="card-header">
|
||||||
<div className="card-heading">
|
<div className="card-heading">
|
||||||
<h4 className="card-title">Default URL</h4>
|
<h4 className="card-title" style={{textTransform: 'none'}}>{defaultUrl}</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-body">
|
{/*<div className="card-body">*/}
|
||||||
<div className="form-group">
|
{/* <div className="form-group">*/}
|
||||||
{/*<label htmlFor="exampleInputEmail1">Email address</label>*/}
|
{/* /!*<label htmlFor="exampleInputEmail1">Email address</label>*!/*/}
|
||||||
<input type="email" className="form-control"
|
{/* <input type="email" className="form-control"*/}
|
||||||
aria-describedby="defaultUrlHelp" value={defaultUrl} readOnly={true} />
|
{/* aria-describedby="defaultUrlHelp" value={defaultUrl} readOnly={true} />*/}
|
||||||
</div>
|
{/* </div>*/}
|
||||||
{/*<button type="submit" className="btn btn-primary">Submit</button>*/}
|
{/*</div>*/}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Formik
|
<Formik
|
||||||
@@ -69,36 +68,42 @@ const URLConfiguration = ({productData}) => {
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
>
|
>
|
||||||
{(props) => {
|
{(props) => {
|
||||||
return (
|
return (
|
||||||
<Form className='w-full'>
|
<Form className='w-full'>
|
||||||
<div className="card card-statistics" style={{backgroundColor:'#7affd92b'}}>
|
<div className="card card-statistics" style={{backgroundColor: '#7affd92b'}}>
|
||||||
<div className="card-header">
|
<div className="card-header">
|
||||||
<div className="card-heading">
|
<div className="card-heading">
|
||||||
<h4 className="card-title" style={{textTransform: 'none'}}>Set your own URL</h4>
|
<h4 className="card-title" style={{textTransform: 'none'}}>Set your own URL</h4>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div className="card-body">
|
||||||
<div className="card-body">
|
<div className="form-group">
|
||||||
<div className="form-group">
|
<label htmlFor="exampleInputEmail1">Enter your full URL <span
|
||||||
<label htmlFor="exampleInputEmail1">Enter your full URL <span className={`${(props.errors.url && props.touched.url) && 'text-danger'}`}>{props.errors.url}</span></label>
|
className={`${(props.errors.url && props.touched.url) && 'text-danger'}`}>{props.errors.url}</span></label>
|
||||||
<input value={props.values.url} onChange={props.handleChange} type="text" className="form-control" id="url" aria-describedby="url" placeholder="https://example.mysite.com"/>
|
<input value={props.values.url} onChange={props.handleChange} type="text"
|
||||||
|
className="form-control" id="url" aria-describedby="url"
|
||||||
|
placeholder="https://example.mysite.com"/>
|
||||||
|
</div>
|
||||||
|
<div style={{width: '100%', textAlign: 'right'}}>
|
||||||
|
<button type="submit" disabled={setURL.isPending}
|
||||||
|
className="btn btn-primary">{setURL.isPending ? 'Loading...' : 'Submit'}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" disabled={setURL.isPending} className="btn btn-primary">{setURL.isPending ? 'Loading...' : 'Submit'}</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{setURL.error &&
|
{setURL.error &&
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<p className='text-danger'>{setURL.error.message}</p>
|
<p className='text-danger'>{setURL.error.message}</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
{setURL.isSuccess &&
|
{setURL.isSuccess &&
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<p className='text-success'>{'Completed successfully'}</p>
|
<p className='text-success'>{'Completed successfully'}</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
</Formik>
|
</Formik>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user