Refresh static image slots from the website catalog.
The dashboard can import and drop slots from the live site instead of creating them by hand. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
36180cda2b
commit
b861ab3dc1
@@ -104,6 +104,7 @@
|
|||||||
gap: 12px;
|
gap: 12px;
|
||||||
padding: 10px 14px;
|
padding: 10px 14px;
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
|
border: 1px solid transparent;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
@@ -118,17 +119,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.navItem.active {
|
.navItem.active {
|
||||||
background: var(--primary);
|
background: rgba(var(--primary-rgb) / 0.1);
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
|
border-color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navItem.active:hover {
|
.navItem.active:hover {
|
||||||
background: var(--primary-dark);
|
background: rgba(var(--primary-rgb) / 0.16);
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navItem.active .chevron {
|
.navItem.active .chevron {
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navGroupBtn {
|
.navGroupBtn {
|
||||||
@@ -163,6 +165,7 @@
|
|||||||
display: block;
|
display: block;
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
border: 1px solid transparent;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
@@ -175,13 +178,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.subNavActive {
|
.subNavActive {
|
||||||
background: var(--primary);
|
background: rgba(var(--primary-rgb) / 0.1);
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
|
border-color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.subNavActive:hover {
|
.subNavActive:hover {
|
||||||
background: var(--primary-dark);
|
background: rgba(var(--primary-rgb) / 0.16);
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
|
|||||||
@@ -1351,7 +1351,7 @@ const en = {
|
|||||||
'website.staticImages.subtitle':
|
'website.staticImages.subtitle':
|
||||||
'Websites load these by key from GET /tenants/{domain}/website/static-images',
|
'Websites load these by key from GET /tenants/{domain}/website/static-images',
|
||||||
'website.staticImages.loading': 'Loading static images...',
|
'website.staticImages.loading': 'Loading static images...',
|
||||||
'website.staticImages.empty': 'No image slots yet for this website.',
|
'website.staticImages.empty': 'No image slots yet. Refresh to read them from the website.',
|
||||||
'website.staticImages.emptyPage': 'No static images on this page yet.',
|
'website.staticImages.emptyPage': 'No static images on this page yet.',
|
||||||
'website.staticImages.errorLoad': 'Unable to load static images.',
|
'website.staticImages.errorLoad': 'Unable to load static images.',
|
||||||
'website.staticImages.errorCreate': 'Unable to create image slot.',
|
'website.staticImages.errorCreate': 'Unable to create image slot.',
|
||||||
@@ -1360,11 +1360,16 @@ const en = {
|
|||||||
'website.staticImages.errorUpload': 'Unable to upload image.',
|
'website.staticImages.errorUpload': 'Unable to upload image.',
|
||||||
'website.staticImages.errorAddImage': 'Unable to save image.',
|
'website.staticImages.errorAddImage': 'Unable to save image.',
|
||||||
'website.staticImages.errorRemoveImage': 'Unable to remove image.',
|
'website.staticImages.errorRemoveImage': 'Unable to remove image.',
|
||||||
|
'website.staticImages.errorRefresh': 'Unable to read image slots from the website.',
|
||||||
'website.staticImages.toastCreated': 'Image slot created.',
|
'website.staticImages.toastCreated': 'Image slot created.',
|
||||||
'website.staticImages.toastUpdated': 'Image slot updated.',
|
'website.staticImages.toastUpdated': 'Image slot updated.',
|
||||||
'website.staticImages.toastDeleted': 'Image slot deleted.',
|
'website.staticImages.toastDeleted': 'Image slot deleted.',
|
||||||
'website.staticImages.toastImageSaved': 'Image saved.',
|
'website.staticImages.toastImageSaved': 'Image saved.',
|
||||||
'website.staticImages.toastImageRemoved': 'Image removed.',
|
'website.staticImages.toastImageRemoved': 'Image removed.',
|
||||||
|
'website.staticImages.toastRefreshed':
|
||||||
|
'{created} slots added, {deleted} removed.',
|
||||||
|
'website.staticImages.toastRefreshedNone': 'No new slots. The list is up to date.',
|
||||||
|
'website.staticImages.refresh': 'Refresh slots from website',
|
||||||
'website.staticImages.addSlot': 'Add image slot',
|
'website.staticImages.addSlot': 'Add image slot',
|
||||||
'website.staticImages.createTitle': 'Add image slot',
|
'website.staticImages.createTitle': 'Add image slot',
|
||||||
'website.staticImages.editTitle': 'Edit image slot',
|
'website.staticImages.editTitle': 'Edit image slot',
|
||||||
@@ -3286,7 +3291,7 @@ const fa: Record<MessageKey, string> = {
|
|||||||
'website.staticImages.subtitle':
|
'website.staticImages.subtitle':
|
||||||
'وبسایتها این تصاویر را با کلید از GET /tenants/{domain}/website/static-images میخوانند',
|
'وبسایتها این تصاویر را با کلید از GET /tenants/{domain}/website/static-images میخوانند',
|
||||||
'website.staticImages.loading': 'در حال بارگذاری تصاویر ثابت...',
|
'website.staticImages.loading': 'در حال بارگذاری تصاویر ثابت...',
|
||||||
'website.staticImages.empty': 'هنوز اسلاتی برای این وبسایت نیست.',
|
'website.staticImages.empty': 'هنوز اسلاتی نیست. تازهسازی را بزنید تا از وبسایت خوانده شود.',
|
||||||
'website.staticImages.emptyPage': 'در این صفحه هنوز تصویر ثابتی نیست.',
|
'website.staticImages.emptyPage': 'در این صفحه هنوز تصویر ثابتی نیست.',
|
||||||
'website.staticImages.errorLoad': 'بارگذاری تصاویر ثابت ممکن نشد.',
|
'website.staticImages.errorLoad': 'بارگذاری تصاویر ثابت ممکن نشد.',
|
||||||
'website.staticImages.errorCreate': 'ساخت اسلات تصویر ممکن نشد.',
|
'website.staticImages.errorCreate': 'ساخت اسلات تصویر ممکن نشد.',
|
||||||
@@ -3295,11 +3300,16 @@ const fa: Record<MessageKey, string> = {
|
|||||||
'website.staticImages.errorUpload': 'آپلود تصویر ممکن نشد.',
|
'website.staticImages.errorUpload': 'آپلود تصویر ممکن نشد.',
|
||||||
'website.staticImages.errorAddImage': 'ذخیره تصویر ممکن نشد.',
|
'website.staticImages.errorAddImage': 'ذخیره تصویر ممکن نشد.',
|
||||||
'website.staticImages.errorRemoveImage': 'حذف تصویر ممکن نشد.',
|
'website.staticImages.errorRemoveImage': 'حذف تصویر ممکن نشد.',
|
||||||
|
'website.staticImages.errorRefresh': 'خواندن اسلاتها از وبسایت ممکن نشد.',
|
||||||
'website.staticImages.toastCreated': 'اسلات تصویر ساخته شد.',
|
'website.staticImages.toastCreated': 'اسلات تصویر ساخته شد.',
|
||||||
'website.staticImages.toastUpdated': 'اسلات تصویر بهروز شد.',
|
'website.staticImages.toastUpdated': 'اسلات تصویر بهروز شد.',
|
||||||
'website.staticImages.toastDeleted': 'اسلات تصویر حذف شد.',
|
'website.staticImages.toastDeleted': 'اسلات تصویر حذف شد.',
|
||||||
'website.staticImages.toastImageSaved': 'تصویر ذخیره شد.',
|
'website.staticImages.toastImageSaved': 'تصویر ذخیره شد.',
|
||||||
'website.staticImages.toastImageRemoved': 'تصویر حذف شد.',
|
'website.staticImages.toastImageRemoved': 'تصویر حذف شد.',
|
||||||
|
'website.staticImages.toastRefreshed':
|
||||||
|
'{created} اسلات اضافه و {deleted} اسلات حذف شد.',
|
||||||
|
'website.staticImages.toastRefreshedNone': 'اسلات جدیدی نبود. فهرست بهروز است.',
|
||||||
|
'website.staticImages.refresh': 'تازهسازی اسلاتها از وبسایت',
|
||||||
'website.staticImages.addSlot': 'افزودن اسلات تصویر',
|
'website.staticImages.addSlot': 'افزودن اسلات تصویر',
|
||||||
'website.staticImages.createTitle': 'افزودن اسلات تصویر',
|
'website.staticImages.createTitle': 'افزودن اسلات تصویر',
|
||||||
'website.staticImages.editTitle': 'ویرایش اسلات تصویر',
|
'website.staticImages.editTitle': 'ویرایش اسلات تصویر',
|
||||||
|
|||||||
@@ -78,3 +78,20 @@
|
|||||||
background-size: var(--select-arrow-size);
|
background-size: var(--select-arrow-size);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.headerTools {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 12px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spin {
|
||||||
|
animation: spin 0.8s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { Pencil, Trash2 } from 'lucide-react'
|
import { Pencil, RefreshCw, Trash2 } from 'lucide-react'
|
||||||
import {
|
import {
|
||||||
AddWebsiteSliderSlideModal,
|
AddWebsiteSliderSlideModal,
|
||||||
type WebsiteSliderSlideFormData,
|
type WebsiteSliderSlideFormData,
|
||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
deleteWebsiteStaticImageSlot,
|
deleteWebsiteStaticImageSlot,
|
||||||
listWebsiteStaticImageSlots,
|
listWebsiteStaticImageSlots,
|
||||||
staticImageItemsToPayload,
|
staticImageItemsToPayload,
|
||||||
|
syncWebsiteStaticImageSlots,
|
||||||
updateWebsiteStaticImageSlot,
|
updateWebsiteStaticImageSlot,
|
||||||
} from '../services/websiteStaticImageService'
|
} from '../services/websiteStaticImageService'
|
||||||
import type {
|
import type {
|
||||||
@@ -79,6 +80,7 @@ export function WebsiteStaticImagesPage() {
|
|||||||
const [slots, setSlots] = useState<WebsiteStaticImageSlot[]>([])
|
const [slots, setSlots] = useState<WebsiteStaticImageSlot[]>([])
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
const [isSaving, setIsSaving] = useState(false)
|
const [isSaving, setIsSaving] = useState(false)
|
||||||
|
const [isSyncing, setIsSyncing] = useState(false)
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
const [pageKey, setPageKey] = useState('home')
|
const [pageKey, setPageKey] = useState('home')
|
||||||
const [editSlot, setEditSlot] = useState<WebsiteStaticImageSlot | null>(null)
|
const [editSlot, setEditSlot] = useState<WebsiteStaticImageSlot | null>(null)
|
||||||
@@ -117,6 +119,33 @@ export function WebsiteStaticImagesPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleRefreshSlots() {
|
||||||
|
setIsSyncing(true)
|
||||||
|
setError('')
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await syncWebsiteStaticImageSlots()
|
||||||
|
setSlots(result.items)
|
||||||
|
showToast(
|
||||||
|
result.created > 0 || result.deleted > 0
|
||||||
|
? t('website.staticImages.toastRefreshed', {
|
||||||
|
created: result.created,
|
||||||
|
deleted: result.deleted,
|
||||||
|
})
|
||||||
|
: t('website.staticImages.toastRefreshedNone'),
|
||||||
|
'success',
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof ApiError) {
|
||||||
|
setError(err.message)
|
||||||
|
} else {
|
||||||
|
setError(t('website.staticImages.errorRefresh'))
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setIsSyncing(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function replaceSlot(updated: WebsiteStaticImageSlot) {
|
function replaceSlot(updated: WebsiteStaticImageSlot) {
|
||||||
setSlots((prev) => prev.map((entry) => (entry.id === updated.id ? updated : entry)))
|
setSlots((prev) => prev.map((entry) => (entry.id === updated.id ? updated : entry)))
|
||||||
}
|
}
|
||||||
@@ -285,23 +314,36 @@ export function WebsiteStaticImagesPage() {
|
|||||||
{t('website.staticImages.subtitle', { domain })}
|
{t('website.staticImages.subtitle', { domain })}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{pageOptions.length > 1 ? (
|
<div className={styles.headerTools}>
|
||||||
<div className={styles.pageSelect}>
|
<Tooltip label={t('website.staticImages.refresh')}>
|
||||||
<label htmlFor="static-images-page">{t('website.staticImages.page')}</label>
|
<button
|
||||||
<select
|
type="button"
|
||||||
id="static-images-page"
|
className={controlStyles.controlBtn}
|
||||||
value={pageKey}
|
onClick={() => void handleRefreshSlots()}
|
||||||
onChange={(e) => setPageKey(e.target.value)}
|
disabled={isLoading || isSaving || isSyncing}
|
||||||
disabled={isLoading}
|
aria-label={t('website.staticImages.refresh')}
|
||||||
>
|
>
|
||||||
{pageOptions.map((option) => (
|
<RefreshCw size={16} className={isSyncing ? styles.spin : undefined} />
|
||||||
<option key={option} value={option}>
|
</button>
|
||||||
{staticImagePageLabel(option, t)}
|
</Tooltip>
|
||||||
</option>
|
{pageOptions.length > 1 ? (
|
||||||
))}
|
<div className={styles.pageSelect}>
|
||||||
</select>
|
<label htmlFor="static-images-page">{t('website.staticImages.page')}</label>
|
||||||
</div>
|
<select
|
||||||
) : null}
|
id="static-images-page"
|
||||||
|
value={pageKey}
|
||||||
|
onChange={(e) => setPageKey(e.target.value)}
|
||||||
|
disabled={isLoading || isSyncing}
|
||||||
|
>
|
||||||
|
{pageOptions.map((option) => (
|
||||||
|
<option key={option} value={option}>
|
||||||
|
{staticImagePageLabel(option, t)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && <p className={specialStyles.error}>{error}</p>}
|
{error && <p className={specialStyles.error}>{error}</p>}
|
||||||
|
|||||||
@@ -37,6 +37,19 @@ export async function createWebsiteStaticImageSlot(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function syncWebsiteStaticImageSlots() {
|
||||||
|
return apiRequest<{
|
||||||
|
message: string
|
||||||
|
created: number
|
||||||
|
updated: number
|
||||||
|
deleted: number
|
||||||
|
items: WebsiteStaticImageSlot[]
|
||||||
|
}>(businessPath('/sync'), {
|
||||||
|
method: 'POST',
|
||||||
|
auth: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function updateWebsiteStaticImageSlot(
|
export async function updateWebsiteStaticImageSlot(
|
||||||
slotId: string,
|
slotId: string,
|
||||||
payload: UpdateWebsiteStaticImageSlotPayload,
|
payload: UpdateWebsiteStaticImageSlotPayload,
|
||||||
|
|||||||
@@ -101,6 +101,7 @@
|
|||||||
gap: 12px;
|
gap: 12px;
|
||||||
padding: 10px 14px;
|
padding: 10px 14px;
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
|
border: 1px solid transparent;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
@@ -115,17 +116,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.navItem.active {
|
.navItem.active {
|
||||||
background: var(--primary);
|
background: rgba(var(--primary-rgb) / 0.1);
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
|
border-color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navItem.active:hover {
|
.navItem.active:hover {
|
||||||
background: var(--primary-dark);
|
background: rgba(var(--primary-rgb) / 0.16);
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navItem.active .chevron {
|
.navItem.active .chevron {
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navGroupBtn {
|
.navGroupBtn {
|
||||||
@@ -160,6 +162,7 @@
|
|||||||
display: block;
|
display: block;
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
border: 1px solid transparent;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
@@ -172,13 +175,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.subNavActive {
|
.subNavActive {
|
||||||
background: var(--primary);
|
background: rgba(var(--primary-rgb) / 0.1);
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
|
border-color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.subNavActive:hover {
|
.subNavActive:hover {
|
||||||
background: var(--primary-dark);
|
background: rgba(var(--primary-rgb) / 0.16);
|
||||||
color: #fff;
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
|
|||||||
@@ -298,6 +298,7 @@ Products accept optional `brandId` on create/update.
|
|||||||
- `GET/POST/PATCH/DELETE /businesses/:businessId/website/brand-groups` — groups with `brandIds[]`
|
- `GET/POST/PATCH/DELETE /businesses/:businessId/website/brand-groups` — groups with `brandIds[]`
|
||||||
- `GET /tenants/:host/website/category-groups` — public category groups
|
- `GET /tenants/:host/website/category-groups` — public category groups
|
||||||
- `GET/POST/PATCH/DELETE /businesses/:businessId/website/static-images` — named image slots (`single` or `list`) with `pageKey` + per-image `titleFa` / `titleEn` / `subtext` / `linkUrl`
|
- `GET/POST/PATCH/DELETE /businesses/:businessId/website/static-images` — named image slots (`single` or `list`) with `pageKey` + per-image `titleFa` / `titleEn` / `subtext` / `linkUrl`
|
||||||
|
- `POST /businesses/:businessId/website/static-images/sync` — read slot keys from the live website (`GET https://{domain}/meshkee/static-image-slots`) and upsert them
|
||||||
- `GET /tenants/:host/website/static-images` — public slots (`?pageKey=home` to filter by page)
|
- `GET /tenants/:host/website/static-images` — public slots (`?pageKey=home` to filter by page)
|
||||||
- `GET /tenants/:host/website/static-images/:key` — one public slot
|
- `GET /tenants/:host/website/static-images/:key` — one public slot
|
||||||
- `GET/POST/PATCH/DELETE /businesses/:businessId/website/sliders` — sliders with `slides[]` (imageMediaId, title, linkUrl)
|
- `GET/POST/PATCH/DELETE /businesses/:businessId/website/sliders` — sliders with `slides[]` (imageMediaId, title, linkUrl)
|
||||||
|
|||||||
Reference in New Issue
Block a user