import React, { useRef, useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import { useFormik } from 'formik';
import * as Yup from 'yup';
import { browseDirectory } from 'providers/ReduxStore/slices/collections/actions';
import Modal from 'components/Modal';
import { IconAlertTriangle, IconArrowRight, IconCaretDown, IconCaretRight, IconCopy } from '@tabler/icons';
import toast from 'react-hot-toast';
const TranslationLog = ({ translationLog }) => {
const [showDetails, setShowDetails] = useState(false);
const preventSetShowDetails = (e) => {
e.stopPropagation();
e.preventDefault();
setShowDetails(!showDetails);
};
const copyClipboard = (e, value) => {
e.stopPropagation();
e.preventDefault();
navigator.clipboard.writeText(value);
toast.success('Copied to clipboard');
};
return (
Warning: Some commands were not translated.{' '}
{showDetails && (
Impacted Collections: {Object.keys(translationLog || {}).length}
Impacted Lines:{' '}
{Object.values(translationLog || {}).reduce(
(acc, curr) => acc + (curr.script?.length || 0) + (curr.test?.length || 0),
0
)}
The numbers after 'script' and 'test' indicate the line numbers of incomplete translations.
{Object.entries(translationLog || {}).map(([name, value]) => (
-
{name}
{value.script && (
script :
{value.script.map((scriptValue, index) => (
{scriptValue}
{index < value.script.length - 1 && <> - >}
))}
)}
{value.test && (
test :
{value.test.map((testValue, index) => (
{testValue}
{index < value.test.length - 1 && <> - >}
))}
)}
))}
)}
);
};
const ImportCollectionLocation = ({ onClose, handleSubmit, collectionName, translationLog }) => {
const inputRef = useRef();
const dispatch = useDispatch();
const formik = useFormik({
enableReinitialize: true,
initialValues: {
collectionLocation: ''
},
validationSchema: Yup.object({
collectionLocation: Yup.string()
.min(1, 'must be at least 1 character')
.max(500, 'must be 500 characters or less')
.required('name is required')
}),
onSubmit: (values) => {
handleSubmit(values.collectionLocation);
}
});
const browse = () => {
dispatch(browseDirectory())
.then((dirPath) => {
formik.setFieldValue('collectionLocation', dirPath);
})
.catch((error) => {
formik.setFieldValue('collectionLocation', '');
console.error(error);
});
};
useEffect(() => {
if (inputRef && inputRef.current) {
inputRef.current.focus();
}
}, [inputRef]);
const onSubmit = () => formik.handleSubmit();
return (
);
};
export default ImportCollectionLocation;