feat(modules): add Mobile Icon and Accent Color editing to EditModuleModal

This commit is contained in:
Urvish Prajapati 2026-12-03 15:24:46 +05:30
parent 167b22d3ec
commit 0673006d12
2 changed files with 89 additions and 2 deletions

View File

@ -106,6 +106,8 @@ export default function App() {
const [editModuleName, setEditModuleName] = useState<string>(''); const [editModuleName, setEditModuleName] = useState<string>('');
const [editModuleDesc, setEditModuleDesc] = useState<string>(''); const [editModuleDesc, setEditModuleDesc] = useState<string>('');
const [editModuleCategory, setEditModuleCategory] = useState<string>('point'); const [editModuleCategory, setEditModuleCategory] = useState<string>('point');
const [editModuleIcon, setEditModuleIcon] = useState<string>('folder-outline');
const [editModuleColor, setEditModuleColor] = useState<string>('#4F46E5');
const [editModuleSaving, setEditModuleSaving] = useState<boolean>(false); const [editModuleSaving, setEditModuleSaving] = useState<boolean>(false);
// Plans State // Plans State
@ -543,6 +545,8 @@ export default function App() {
setEditModuleName(mod.name || ''); setEditModuleName(mod.name || '');
setEditModuleDesc(mod.description || ''); setEditModuleDesc(mod.description || '');
setEditModuleCategory(normalizeCategory(mod.category)); setEditModuleCategory(normalizeCategory(mod.category));
setEditModuleIcon(mod.icon || 'folder-outline');
setEditModuleColor(mod.color || '#4F46E5');
}; };
const handleSaveModuleDetails = async (e: React.FormEvent) => { const handleSaveModuleDetails = async (e: React.FormEvent) => {
@ -550,6 +554,8 @@ export default function App() {
if (!selectedEditModule || !userToken) return; if (!selectedEditModule || !userToken) return;
setEditModuleSaving(true); setEditModuleSaving(true);
const normalizedCat = normalizeCategory(editModuleCategory); const normalizedCat = normalizeCategory(editModuleCategory);
const nextIcon = editModuleIcon.trim() || 'folder-outline';
const nextColor = editModuleColor.trim() || '#4F46E5';
try { try {
await axios.put( await axios.put(
`${API_BASE}/api/admin/modules/${selectedEditModule.id}`, `${API_BASE}/api/admin/modules/${selectedEditModule.id}`,
@ -557,13 +563,22 @@ export default function App() {
name: editModuleName, name: editModuleName,
description: editModuleDesc, description: editModuleDesc,
category: normalizedCat, category: normalizedCat,
icon: nextIcon,
color: nextColor,
}, },
{ headers: { Authorization: `Bearer ${userToken}` } } { headers: { Authorization: `Bearer ${userToken}` } }
); );
setAdminModulesList((prev) => setAdminModulesList((prev) =>
prev.map((m) => prev.map((m) =>
m.id === selectedEditModule.id m.id === selectedEditModule.id
? { ...m, name: editModuleName, description: editModuleDesc, category: normalizedCat } ? {
...m,
name: editModuleName,
description: editModuleDesc,
category: normalizedCat,
icon: nextIcon,
color: nextColor,
}
: m : m
) )
); );
@ -1322,9 +1337,13 @@ export default function App() {
name={editModuleName} name={editModuleName}
description={editModuleDesc} description={editModuleDesc}
category={editModuleCategory} category={editModuleCategory}
icon={editModuleIcon}
color={editModuleColor}
saving={editModuleSaving} saving={editModuleSaving}
onNameChange={setEditModuleName} onNameChange={setEditModuleName}
onDescriptionChange={setEditModuleDesc} onDescriptionChange={setEditModuleDesc}
onIconChange={setEditModuleIcon}
onColorChange={setEditModuleColor}
onSave={handleSaveModuleDetails} onSave={handleSaveModuleDetails}
onClose={() => setSelectedEditModule(null)} onClose={() => setSelectedEditModule(null)}
/> />

View File

@ -3,14 +3,29 @@ import { XCircle, RefreshCw } from 'lucide-react';
import type { ModuleItem } from '../../types'; import type { ModuleItem } from '../../types';
import { normalizeCategory } from '../../utils/category'; import { normalizeCategory } from '../../utils/category';
const ICON_PRESETS = [
'medkit-outline',
'heart-outline',
'woman-outline',
'ear-outline',
'body-outline',
'leaf-outline',
'pulse-outline',
'folder-outline',
];
interface EditModuleModalProps { interface EditModuleModalProps {
module: ModuleItem | null; module: ModuleItem | null;
name: string; name: string;
description: string; description: string;
category: string; category: string;
icon: string;
color: string;
saving: boolean; saving: boolean;
onNameChange: (val: string) => void; onNameChange: (val: string) => void;
onDescriptionChange: (val: string) => void; onDescriptionChange: (val: string) => void;
onIconChange: (val: string) => void;
onColorChange: (val: string) => void;
onSave: (e: React.FormEvent) => void; onSave: (e: React.FormEvent) => void;
onClose: () => void; onClose: () => void;
} }
@ -20,9 +35,13 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
name, name,
description, description,
category, category,
icon,
color,
saving, saving,
onNameChange, onNameChange,
onDescriptionChange, onDescriptionChange,
onIconChange,
onColorChange,
onSave, onSave,
onClose, onClose,
}) => { }) => {
@ -35,7 +54,7 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<div <div
className="h-8 w-8 rounded-lg flex items-center justify-center font-bold text-white text-xs" className="h-8 w-8 rounded-lg flex items-center justify-center font-bold text-white text-xs"
style={{ backgroundColor: (module as any).color || '#6366F1' }} style={{ backgroundColor: color || (module as any).color || '#4F46E5' }}
> >
{(module.name || 'M')[0].toUpperCase()} {(module.name || 'M')[0].toUpperCase()}
</div> </div>
@ -89,6 +108,55 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
/> />
</div> </div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Mobile Icon (Ionicons)</label>
<input
type="text"
value={icon}
onChange={(e) => onIconChange(e.target.value)}
placeholder="e.g. medkit-outline"
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-mono text-slate-800 focus:outline-none focus:border-indigo-500"
/>
</div>
<div>
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Mobile Accent Color</label>
<div className="flex items-center gap-2">
<input
type="color"
value={/^#[0-9A-Fa-f]{6}$/.test(color) ? color : '#4F46E5'}
onChange={(e) => onColorChange(e.target.value)}
className="h-9 w-10 rounded-lg border border-slate-200 cursor-pointer p-0.5 bg-white"
/>
<input
type="text"
value={color}
onChange={(e) => onColorChange(e.target.value)}
placeholder="#4F46E5"
className="flex-1 bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-mono text-slate-800 focus:outline-none focus:border-indigo-500"
/>
</div>
</div>
</div>
<div className="flex flex-wrap gap-1.5">
{ICON_PRESETS.map((preset) => (
<button
key={preset}
type="button"
onClick={() => onIconChange(preset)}
className={`px-2 py-1 rounded-lg text-[10px] font-mono border transition-colors cursor-pointer ${
icon === preset
? 'bg-indigo-50 text-indigo-700 border-indigo-300 font-bold'
: 'bg-slate-50 text-slate-600 border-slate-200 hover:bg-slate-100'
}`}
>
{preset}
</button>
))}
</div>
<div className="flex gap-2 pt-2"> <div className="flex gap-2 pt-2">
<button <button
type="button" type="button"