populated external URL #93
@@ -2,19 +2,34 @@ 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';
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
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}) => {
|
||||||
|
|
||||||
|
const [externalURLChanged, setExternalURLChanged] = useState(true)
|
||||||
|
|
||||||
|
const initialValues = {
|
||||||
|
url: productData?.external_url || '',
|
||||||
|
};
|
||||||
|
|
||||||
let defaultUrl = 'https://' + productData?.internal_url
|
let defaultUrl = 'https://' + productData?.internal_url
|
||||||
let externaltUrl = productData?.external_url
|
let externalUrl = productData?.external_url
|
||||||
|
|
||||||
|
const handleExternalURLChanged = (e) => {
|
||||||
|
if(e.target.value == externalUrl){
|
||||||
|
setExternalURLChanged(true)
|
||||||
|
}else{
|
||||||
|
setExternalURLChanged(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// API to set url
|
// API to set url
|
||||||
const setURL = useMutation({
|
const setURL = useMutation({
|
||||||
@@ -81,13 +96,18 @@ const URLConfiguration = ({productData}) => {
|
|||||||
<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"
|
<input value={props.values.url} onChange={(e)=>{props.handleChange(e); handleExternalURLChanged(e)}} type="text"
|
||||||
className="form-control" id="url" aria-describedby="url"
|
className="form-control" id="url" aria-describedby="url"
|
||||||
placeholder="https://example.mysite.com"/>
|
placeholder="https://example.mysite.com"/>
|
||||||
</div>
|
</div>
|
||||||
<div style={{width: '100%', textAlign: 'right'}}>
|
<div style={{width: '100%', textAlign: 'right'}}>
|
||||||
<button type="submit" disabled={setURL.isPending}
|
<button
|
||||||
className="btn btn-primary">{setURL.isPending ? 'Loading...' : 'Submit'}</button>
|
type="submit"
|
||||||
|
disabled={setURL.isPending || externalURLChanged}
|
||||||
|
className="btn btn-primary"
|
||||||
|
>
|
||||||
|
{setURL.isPending ? 'Loading...' : 'Submit'}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user