feat: dynamic UI texts system + admin panel editor + Vazirmatn local font + bug fixes
- Add getText() system for all homepage sections (Header, Hero, FeaturedProducts, SmartAdvisor, VetGallery, Footer)
- Add UITexts admin page in frontend/admin-panel with search, group collapse, per-key save
- Add seed-ui-texts.ts with 102 texts in 9 groups
- Add local VazirmatnVariable.woff2 font, remove CDN + Inter references
- Fix hero image path, productService return type { data, meta }
- Fix ArchivePage pagination + CATEGORIES list + breadcrumbs
- Fix BlogPage/Wiki page links + brightness-0 invert removal
- Fix IngredientWiki search + product links + placeholder
- Fix all getProducts() callers for { data } destructuring
- Fix sitemap.ts, CartDrawer, B2BPortal, CheckoutPage type issues
- Add .gitignore for /fonts/ and /backend/uploads/
This commit is contained in:
1 parent
ab7ed279c8
commit
1a0c98a34e
26 files changed
+653
-132
No files matched your search
@@ -14,6 +14,7 @@ import Categories from './pages/Categories';
|
||||
import Blogs from './pages/Blogs';
|
||||
import Wiki from './pages/Wiki';
|
||||
import Pets from './pages/Pets';
|
||||
import UITexts from './pages/UITexts';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@@ -33,7 +34,8 @@ function App() {
|
||||
<Route path="categories" element={<Categories />} />
|
||||
<Route path="blogs" element={<Blogs />} />
|
||||
<Route path="wiki" element={<Wiki />} />
|
||||
<Route path="pets" element={<Pets />} />
|
||||
<Route path="pets" element={<Pets />} />
|
||||
<Route path="ui-texts" element={<UITexts />} />
|
||||
</Route>
|
||||
</Route>
|
||||
</Routes>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { Home, Users, ShoppingBag, ShoppingCart, Tag, Settings, LogOut, TrendingUp, FolderTree, FileText, BookOpen, Heart, Package, LayoutDashboard } from 'lucide-react';
|
||||
import { Home, Users, ShoppingBag, ShoppingCart, Tag, Settings, LogOut, TrendingUp, FolderTree, FileText, BookOpen, Heart, Package, LayoutDashboard, Languages } from 'lucide-react';
|
||||
|
||||
const menuGroups = [
|
||||
{
|
||||
@@ -36,6 +36,7 @@ const menuGroups = [
|
||||
title: 'سیستم',
|
||||
items: [
|
||||
{ icon: Settings, label: 'تنظیمات', path: '/settings' },
|
||||
{ icon: Languages, label: 'متون رابط کاربری', path: '/ui-texts' },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Languages, Save, Search, CheckCircle, Loader2 } from 'lucide-react';
|
||||
import api from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
|
||||
const GROUPS: Record<string, string[]> = {
|
||||
"هدر و ناوبری": [
|
||||
"shipping_notice", "brand_name_fa", "brand_subtitle",
|
||||
"nav_solutions", "nav_products", "nav_wiki", "nav_blog", "nav_pet_profiles",
|
||||
"nav_search_placeholder", "nav_search_button", "nav_pet_switcher_title",
|
||||
"nav_register_pet", "nav_wallet_orders", "nav_logout", "nav_login", "nav_cart",
|
||||
],
|
||||
"بنر اصلی (Hero)": [
|
||||
"hero_badge", "hero_title", "hero_desc",
|
||||
"hero_btn_advisor", "hero_btn_products",
|
||||
"hero_image_badge", "hero_image_title", "hero_quality_standard",
|
||||
"hero_stat_founded", "hero_stat_agencies", "hero_stat_german_formula",
|
||||
],
|
||||
"دستیار سلامت": [
|
||||
"advisor_badge", "advisor_title", "advisor_subtitle",
|
||||
"advisor_step1_title", "advisor_step1_desc",
|
||||
"advisor_pet_name_label", "advisor_pet_name_placeholder",
|
||||
"advisor_pet_breed_label", "advisor_pet_breed_placeholder",
|
||||
"advisor_submit_btn", "advisor_validation_warning",
|
||||
"advisor_step2_title", "advisor_step2_desc",
|
||||
"advisor_age_label", "advisor_weight_label", "advisor_activity_label",
|
||||
"advisor_back", "advisor_next_final",
|
||||
"advisor_step3_title", "advisor_step3_desc", "advisor_complete",
|
||||
],
|
||||
"محصولات برگزیده": [
|
||||
"featured_badge", "featured_title_line1", "featured_title_line2",
|
||||
"featured_desc", "featured_view_all", "product_view_details",
|
||||
"featured_no_products_title", "featured_no_products_desc",
|
||||
],
|
||||
"ویدئوها": [
|
||||
"videos_badge", "videos_title", "videos_title_highlight",
|
||||
"videos_desc", "videos_view_all",
|
||||
],
|
||||
"کارتهای ناوبری": [
|
||||
"nav_card_shop_title", "nav_card_shop_desc", "nav_card_shop_cta",
|
||||
"nav_card_wiki_title", "nav_card_wiki_desc", "nav_card_wiki_cta",
|
||||
],
|
||||
"درباره ما": [
|
||||
"about_label", "about_title",
|
||||
"about_item1_title", "about_item1_desc",
|
||||
"about_item2_title", "about_item2_desc",
|
||||
"about_item3_title", "about_item3_desc",
|
||||
],
|
||||
"CTA": [
|
||||
"cta_title", "cta_desc", "cta_btn_primary", "cta_btn_secondary",
|
||||
],
|
||||
"فوتر": [
|
||||
"footer_brand_title", "footer_brand_subtitle", "footer_brand_desc",
|
||||
"footer_links_title", "footer_link_products", "footer_link_blog",
|
||||
"footer_link_profiles", "footer_link_wiki", "footer_link_b2b",
|
||||
"footer_contact_title", "footer_phone_label", "footer_phone",
|
||||
"footer_email_label", "footer_email", "footer_address_label", "footer_address",
|
||||
"footer_auth_title", "footer_auth_desc", "footer_auth_badge",
|
||||
"footer_copyright", "footer_about", "footer_contact", "footer_privacy",
|
||||
],
|
||||
};
|
||||
|
||||
export default function UITexts() {
|
||||
const [texts, setTexts] = useState<Record<string, string>>({});
|
||||
const [edits, setEdits] = useState<Record<string, string>>({});
|
||||
const [search, setSearch] = useState("");
|
||||
const [saving, setSaving] = useState<string | null>(null);
|
||||
const [savedKey, setSavedKey] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [expandedGroups, setExpandedGroups] = useState<Set<string>>(() => new Set(Object.keys(GROUPS)));
|
||||
|
||||
useEffect(() => {
|
||||
api.get('/settings/ui-texts').then(res => {
|
||||
const obj: Record<string, string> = {};
|
||||
if (Array.isArray(res.data)) {
|
||||
res.data.forEach((item: { key: string; value: string }) => {
|
||||
obj[item.key] = item.value;
|
||||
});
|
||||
}
|
||||
setTexts(obj);
|
||||
setLoading(false);
|
||||
}).catch(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
const handleChange = (key: string, value: string) => {
|
||||
setEdits(prev => ({ ...prev, [key]: value }));
|
||||
};
|
||||
|
||||
const handleSave = async (key: string) => {
|
||||
const value = edits[key] ?? texts[key];
|
||||
setSaving(key);
|
||||
try {
|
||||
await api.patch(`/settings/ui-texts/${key}`, { value });
|
||||
setTexts(prev => ({ ...prev, [key]: value }));
|
||||
setEdits(prev => { const n = { ...prev }; delete n[key]; return n; });
|
||||
setSavedKey(key);
|
||||
setTimeout(() => setSavedKey(null), 2000);
|
||||
} catch (err) {
|
||||
console.error('Failed to save:', err);
|
||||
} finally {
|
||||
setSaving(null);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleGroup = (group: string) => {
|
||||
setExpandedGroups(prev => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(group)) next.delete(group);
|
||||
else next.add(group);
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
const filteredGroups = Object.entries(GROUPS)
|
||||
.map(([group, keys]) => ({
|
||||
group,
|
||||
keys: keys.filter(k =>
|
||||
!search || k.toLowerCase().includes(search.toLowerCase()) ||
|
||||
(texts[k] || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||
(edits[k] || "").toLowerCase().includes(search.toLowerCase())
|
||||
),
|
||||
}))
|
||||
.filter(g => g.keys.length > 0);
|
||||
|
||||
const unsavedCount = Object.keys(edits).length;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
|
||||
<Languages className="w-6 h-6 text-purple-600" />
|
||||
متون رابط کاربری
|
||||
</h2>
|
||||
<p className="text-gray-500 font-medium mt-1">ویرایش تمامی متون سایت از هدر تا فوتر</p>
|
||||
</div>
|
||||
{unsavedCount > 0 && (
|
||||
<span className="bg-amber-100 text-amber-700 px-3 py-1 rounded-full text-xs font-bold">
|
||||
{unsavedCount} تغییر ذخیره نشده
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="relative">
|
||||
<Search className="absolute right-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="جستجو در کلیدها یا متنها..."
|
||||
value={search}
|
||||
onChange={e => setSearch(e.target.value)}
|
||||
className="w-full bg-white border border-gray-200 rounded-xl py-3 pr-11 pl-4 text-sm focus:outline-none focus:ring-2 focus:ring-purple-500/20"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center p-12"><Spinner size="lg" className="text-purple-600" /></div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{filteredGroups.map(({ group, keys }) => {
|
||||
const isExpanded = expandedGroups.has(group);
|
||||
return (
|
||||
<div key={group} className="bg-white rounded-2xl border border-gray-200 overflow-hidden">
|
||||
<button
|
||||
onClick={() => toggleGroup(group)}
|
||||
className="w-full bg-gray-50 px-6 py-4 border-b border-gray-200 flex items-center justify-between hover:bg-gray-100 transition-colors"
|
||||
>
|
||||
<h3 className="font-black text-gray-800">{group}</h3>
|
||||
<span className="text-xs text-gray-400 font-bold">{keys.length} متن</span>
|
||||
</button>
|
||||
{isExpanded && (
|
||||
<div className="divide-y divide-gray-100">
|
||||
{keys.map(key => {
|
||||
const current = edits[key] !== undefined ? edits[key] : texts[key] || "";
|
||||
const isDirty = edits[key] !== undefined;
|
||||
const isSaved = savedKey === key;
|
||||
const isSavingThis = saving === key;
|
||||
|
||||
return (
|
||||
<div key={key} className="px-6 py-4 flex items-start gap-4">
|
||||
<div className="w-52 shrink-0 pt-2">
|
||||
<code className="text-[10px] text-gray-500 bg-gray-100 px-2 py-1 rounded font-mono break-all">
|
||||
{key}
|
||||
</code>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<textarea
|
||||
value={current}
|
||||
onChange={e => handleChange(key, e.target.value)}
|
||||
rows={current.length > 80 ? 3 : 1}
|
||||
className={`w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-purple-500/20 resize-y transition-colors ${
|
||||
isDirty ? 'border-amber-300 bg-amber-50' : 'border-gray-200 bg-white'
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => handleSave(key)}
|
||||
disabled={!isDirty || isSavingThis}
|
||||
className={`mt-1 p-2 rounded-lg transition-all ${
|
||||
isSaved
|
||||
? 'bg-green-100 text-green-600'
|
||||
: isDirty
|
||||
? 'bg-purple-600 text-white hover:bg-purple-700 shadow-sm'
|
||||
: 'bg-gray-100 text-gray-300 cursor-not-allowed'
|
||||
}`}
|
||||
>
|
||||
{isSavingThis ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user