feat(modules): add Mobile Icon and Accent Color editing to EditModuleModal
This commit is contained in:
parent
167b22d3ec
commit
0673006d12
21
src/App.tsx
21
src/App.tsx
|
|
@ -106,6 +106,8 @@ export default function App() {
|
|||
const [editModuleName, setEditModuleName] = useState<string>('');
|
||||
const [editModuleDesc, setEditModuleDesc] = useState<string>('');
|
||||
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);
|
||||
|
||||
// Plans State
|
||||
|
|
@ -543,6 +545,8 @@ export default function App() {
|
|||
setEditModuleName(mod.name || '');
|
||||
setEditModuleDesc(mod.description || '');
|
||||
setEditModuleCategory(normalizeCategory(mod.category));
|
||||
setEditModuleIcon(mod.icon || 'folder-outline');
|
||||
setEditModuleColor(mod.color || '#4F46E5');
|
||||
};
|
||||
|
||||
const handleSaveModuleDetails = async (e: React.FormEvent) => {
|
||||
|
|
@ -550,6 +554,8 @@ export default function App() {
|
|||
if (!selectedEditModule || !userToken) return;
|
||||
setEditModuleSaving(true);
|
||||
const normalizedCat = normalizeCategory(editModuleCategory);
|
||||
const nextIcon = editModuleIcon.trim() || 'folder-outline';
|
||||
const nextColor = editModuleColor.trim() || '#4F46E5';
|
||||
try {
|
||||
await axios.put(
|
||||
`${API_BASE}/api/admin/modules/${selectedEditModule.id}`,
|
||||
|
|
@ -557,13 +563,22 @@ export default function App() {
|
|||
name: editModuleName,
|
||||
description: editModuleDesc,
|
||||
category: normalizedCat,
|
||||
icon: nextIcon,
|
||||
color: nextColor,
|
||||
},
|
||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
||||
);
|
||||
setAdminModulesList((prev) =>
|
||||
prev.map((m) =>
|
||||
m.id === selectedEditModule.id
|
||||
? { ...m, name: editModuleName, description: editModuleDesc, category: normalizedCat }
|
||||
? {
|
||||
...m,
|
||||
name: editModuleName,
|
||||
description: editModuleDesc,
|
||||
category: normalizedCat,
|
||||
icon: nextIcon,
|
||||
color: nextColor,
|
||||
}
|
||||
: m
|
||||
)
|
||||
);
|
||||
|
|
@ -1322,9 +1337,13 @@ export default function App() {
|
|||
name={editModuleName}
|
||||
description={editModuleDesc}
|
||||
category={editModuleCategory}
|
||||
icon={editModuleIcon}
|
||||
color={editModuleColor}
|
||||
saving={editModuleSaving}
|
||||
onNameChange={setEditModuleName}
|
||||
onDescriptionChange={setEditModuleDesc}
|
||||
onIconChange={setEditModuleIcon}
|
||||
onColorChange={setEditModuleColor}
|
||||
onSave={handleSaveModuleDetails}
|
||||
onClose={() => setSelectedEditModule(null)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -3,14 +3,29 @@ import { XCircle, RefreshCw } from 'lucide-react';
|
|||
import type { ModuleItem } from '../../types';
|
||||
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 {
|
||||
module: ModuleItem | null;
|
||||
name: string;
|
||||
description: string;
|
||||
category: string;
|
||||
icon: string;
|
||||
color: string;
|
||||
saving: boolean;
|
||||
onNameChange: (val: string) => void;
|
||||
onDescriptionChange: (val: string) => void;
|
||||
onIconChange: (val: string) => void;
|
||||
onColorChange: (val: string) => void;
|
||||
onSave: (e: React.FormEvent) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
|
@ -20,9 +35,13 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
|||
name,
|
||||
description,
|
||||
category,
|
||||
icon,
|
||||
color,
|
||||
saving,
|
||||
onNameChange,
|
||||
onDescriptionChange,
|
||||
onIconChange,
|
||||
onColorChange,
|
||||
onSave,
|
||||
onClose,
|
||||
}) => {
|
||||
|
|
@ -35,7 +54,7 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
|||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
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()}
|
||||
</div>
|
||||
|
|
@ -89,6 +108,55 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
|||
/>
|
||||
</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">
|
||||
<button
|
||||
type="button"
|
||||
|
|
|
|||
Loading…
Reference in New Issue