import React, { useEffect, useState } from 'react'; import { __, _n, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import { Card, Button, Badge, Notice, Field, LineChart, Delta } from './ui'; import Explain from './Explain'; /** * The business as the directories know it. * * A "near me" answer is assembled from the directories, not from the site: * Google Business Profile first, Bing Places for Copilot, Apple Business * Connect for Siri and Maps. This tab connects the Google listing through the * Places API — the part of the profile the public sees, on a key from Google * Cloud that works the same afternoon — compares it field by field with the * record on the Profile tab, imports it, and keeps a weekly rating history. * Bing and Apple publish no listing API; they are attached by URL, published * as sameAs, and kept aligned by Bing's own sync from the Google profile. * * @param {object} props * @param {object} props.record The business record (settings). * @param {Function} props.onImported Called after an import so the form reloads. */ export default function LocalListings({ record, onImported }) { const [data, setData] = useState(null); const [error, setError] = useState(null); const [key, setKey] = useState(''); const [query, setQuery] = useState(''); const [found, setFound] = useState(null); const [busy, setBusy] = useState(''); const [imported, setImported] = useState(null); const load = () => api.get('/local-seo/listings').then(setData).catch((e) => setError(e.message)); useEffect(() => { load(); }, []); const run = async (name, fn) => { setBusy(name); setError(null); try { await fn(); } catch (e) { setError(e.message); } finally { setBusy(''); } }; const saveKey = () => run('key', async () => { setData(await api.post('/local-seo/listings', { key })); setKey(''); }); const search = () => run('search', async () => setFound((await api.post('/local-seo/listings/search', { query })).places || [])); const fetch = (placeId) => run('fetch', async () => { setData(await api.post('/local-seo/listings/fetch', { place_id: placeId })); setFound(null); }); const doImport = (overwrite) => run(overwrite ? 'overwrite' : 'import', async () => { const r = await api.post('/local-seo/listings/import', { overwrite }); setData(r); setImported(r.imported || []); onImported && onImported(); }); const forget = () => run('forget', async () => setData(await api.del('/local-seo/listings/google'))); if (!data) return null; const g = data.google; const mismatches = (data.compare || []).filter((c) => c.match === false); const history = (data.history || []).map((h) => ({ label: h.day.slice(5), value: h.reviews, rating: h.rating })); const firstR = data.history?.[0]; const lastR = data.history?.[data.history.length - 1]; return (
{__('Google’s Business Profile management API needs a project reviewed and approved by Google — weeks, and quota zero until then. The Places API answers with a plain key the same afternoon and returns the part of the profile that matters for consistency: name, address, phone, website, hours, rating and review count. Editing the profile stays on Google’s side; this checks and imports.', 'ai-rank-suite')}
| {__('Field', 'ai-rank-suite')} | {__('Your record', 'ai-rank-suite')} | {__('Google', 'ai-rank-suite')} | |
|---|---|---|---|
| {c.label} | {c.ours || '—'} | {c.theirs || '—'} |
{c.match === true ? |
{imported.length ? sprintf(__('Imported: %s. Save the profile to publish.', 'ai-rank-suite'), imported.join(', ')) : __('Nothing to import — every field was already filled.', 'ai-rank-suite')}
)}{sprintf(__('Rating now %s ★', 'ai-rank-suite'), lastR.rating)}{firstR && firstR.rating !== null && firstR !== lastR ? ` ${sprintf(__('(was %1$s ★ on %2$s)', 'ai-rank-suite'), firstR.rating, firstR.day)}` : ''}.
)}{__('Bing Places has an “Import from Google My Business” option in its dashboard that syncs name, address, phone, hours and photos from your Google profile — and can keep syncing. Use it, and the consistency check above covers Bing too.', 'ai-rank-suite')}