import { Box, Button, FormControlLabel, FormLabel, Grid, IconButton, InputAdornment, Paper, Radio, RadioGroup, Stack, Tab, TextField, Typography, } from '@mui/material'; import { useState } from '@wordpress/element'; import { Layout } from '../../layout/Layout'; import { SupplierService } from './SupplierService'; import { useNavigate, useParams } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { Spinner } from '../../components/spinner/Spinner'; import { Field, FieldArray, Form, Formik } from 'formik'; import { Supplier } from './Supplier'; import { LoadingButton, TabContext, TabList, TabPanel } from '@mui/lab'; import * as Yup from 'yup'; import VisibilityIcon from '@mui/icons-material/Visibility'; import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; import DeleteIcon from '@mui/icons-material/Delete'; import Switch from '@mui/material/Switch/Switch'; export const SupplierEdit = () => { const [showSecret, setShowSecret] = useState(false); const [isRefreshing, setRefreshing] = useState(false); const [tab, setTab] = useState('1'); const handleClickShowSecret = () => setShowSecret((show: boolean) => !show); const handleRefresh = () => { setRefreshing(true); SupplierService.refresh(id).then((response) => { setRefreshing(false); }); }; const navigate = useNavigate(); const parent = { label: 'Suppliers', to: '..' }; const radioOptions = [ { label: 'DUNS', value: 'DUNS' }, { label: 'Network ID', value: 'NetworkID' }, ]; const validationSchema = Yup.object().shape({ name: Yup.string().required(), logo: Yup.string().url(), endpoint_base: Yup.string().url().required(), domain_type: Yup.string().required(), domain_identity: Yup.string().required(), domain_secret: Yup.string().required(), prefix: Yup.string(), punchout_identity: Yup.string().required(), punchout_secret: Yup.string().required(), }); const { id } = useParams(); const { data, isFetching } = useQuery({ queryKey: [`supplier-${id}`], queryFn: () => SupplierService.show(id), enabled: !!id, }); return ( {!data && id && isFetching && } {(data || !id) && ( { if (id) { SupplierService.update(id, { ...values }).then( () => { setSubmitting(false); } ); } else { SupplierService.store({ ...values }).then( (response) => { if (response.id) { navigate(`../${response.id}`); } setSubmitting(false); } ); } }} validationSchema={validationSchema} > {({ isSubmitting, errors, touched, values }) => (
Domain type {radioOptions.map((option) => ( } label={option.label} /> ))} {showSecret ? ( ) : ( )} ), }} required fullWidth /> {showSecret ? ( ) : ( )} ), }} required fullWidth /> { setTab(newTab); }} > {({ field }) => ( } label="Update Endpoints Daily" /> )} {id && ( Endpoints ( {values.endpoints.map( ( endpoint, index: number ) => ( arrayHelpers.remove( index ) } /> ) )} )} /> )} {id ? 'Update' : 'Save'} {id && ( Refresh endpoints )}
)}
)}
); };