import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAppStateContext } from '../context/user.data.context'; import Button from '../components/widgets/Button'; import { postWordpressProducts } from '../service/products/products.service'; const ImportIllustration = () => ( ); const ImportProducts = (): JSX.Element => { const [loading, setLoading] = useState(false); const [isError, setIsError] = useState(null); const [isSuccess, setIsSuccess] = useState(null); const { token, user, canUseWpApi, fetchUser } = useAppStateContext(); const navigate = useNavigate(); useEffect(() => { if (!user && token) fetchUser(); }, [user, token, fetchUser]); useEffect(() => { if (isError || isSuccess) { const timer: NodeJS.Timeout = setTimeout(() => { setIsError(null); setIsSuccess(null); }, 4500); return () => clearTimeout(timer); } }, [isError, isSuccess]); const onProductsImport = async (): Promise => { try { setLoading(true); setIsError(null); setIsSuccess(null); const response = await postWordpressProducts(); if (response) { setIsSuccess( 'Your products are being imported. You can leave this page and keep using the plugin.' ); } else { setIsError('We could not start the import. Please try again.'); } } catch (error: any) { setIsError(error?.message || 'Something went wrong. Please try again.'); } finally { setLoading(false); } }; return (

Import Products

Start syncing your store catalog to Recomaze. We’ll handle it in the background so you can continue working.

{loading && (

Import in progress…

This may take up to a minute depending on your catalog size.

)} {!loading && isError && (

Import failed

{isError}

)} {!loading && isSuccess && (

Import started

{isSuccess}

)} {!loading && !isError && !isSuccess && (

Notice:{' '} Existing products in Recomaze will be replaced with the latest data from your shop.

)}
{canUseWpApi ? ( ) : (

You don’t have enough permissions or the WordPress REST API is disabled. Your products may already be synced; otherwise, enable REST API access to use this feature.

)}

You can safely leave this page—the import runs in the background. Check back later to see updated products in your catalog.

); }; export default ImportProducts;