Exercise Creation from Plan fixed

This commit is contained in:
AG
2025-12-12 19:34:17 +02:00
parent 3ede054766
commit e1253f4100
3 changed files with 84 additions and 97 deletions

View File

@@ -59,6 +59,10 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
const [isCreatingEx, setIsCreatingEx] = useState(false);
const [exerciseNameFilter, setExerciseNameFilter] = useState('');
// Admin Confirmation Modal State
type AdminActionType = 'DELETE_USER' | 'BLOCK_USER' | 'UNBLOCK_USER';
const [confirmAction, setConfirmAction] = useState<{ type: AdminActionType, userId: string, email?: string, currentBlockState?: boolean } | null>(null);
const exerciseTypeLabels: Record<ExerciseType, string> = {
[ExerciseType.STRENGTH]: t('type_strength', lang),
[ExerciseType.BODYWEIGHT]: t('type_bodyweight', lang),
@@ -191,16 +195,32 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
}
};
const handleAdminDeleteUser = async (uid: string) => {
if (confirm(t('delete_confirm', lang))) {
await deleteUser(uid);
await refreshUserList();
}
const handleAdminDeleteUser = (uid: string, email: string) => {
setConfirmAction({ type: 'DELETE_USER', userId: uid, email });
};
const handleAdminBlockUser = async (uid: string, isBlocked: boolean) => {
await toggleBlockUser(uid, isBlocked);
await refreshUserList();
const handleAdminBlockUser = (uid: string, isBlocked: boolean, email: string) => {
setConfirmAction({
type: isBlocked ? 'BLOCK_USER' : 'UNBLOCK_USER',
userId: uid,
email,
currentBlockState: isBlocked
});
};
const handleConfirmAction = async () => {
if (!confirmAction) return;
if (confirmAction.type === 'DELETE_USER') {
await deleteUser(confirmAction.userId);
await refreshUserList();
} else if (confirmAction.type === 'BLOCK_USER' || confirmAction.type === 'UNBLOCK_USER') {
// If type is BLOCK_USER, we are passing true to block. If UNBLOCK, false.
// But simpler: we stored currentBlockState which is the target state (e.g. isBlocked=true passed to handler)
await toggleBlockUser(confirmAction.userId, confirmAction.currentBlockState!);
await refreshUserList();
}
setConfirmAction(null);
};
const handleAdminResetPass = async (uid: string) => {
@@ -551,7 +571,7 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
{u.role !== 'ADMIN' && (
<>
<button
onClick={() => handleAdminBlockUser(u.id, !u.isBlocked)}
onClick={() => handleAdminBlockUser(u.id, !u.isBlocked, u.email)}
className={`p-2 rounded-full ${u.isBlocked ? 'bg-primary/20 text-primary' : 'text-on-surface-variant hover:bg-white/10'}`}
title={u.isBlocked ? t('unblock', lang) : t('block', lang)}
aria-label={u.isBlocked ? t('unblock', lang) : t('block', lang)}
@@ -559,7 +579,7 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
<Ban size={18} />
</button>
<button
onClick={() => handleAdminDeleteUser(u.id)}
onClick={() => handleAdminDeleteUser(u.id, u.email)}
className="p-2 text-on-surface-variant hover:text-error hover:bg-error/10 rounded-full"
title={t('delete', lang)}
aria-label={t('delete', lang)}
@@ -649,6 +669,41 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
/>
)}
{/* Admin Confirmation Modal */}
<Modal
isOpen={!!confirmAction}
onClose={() => setConfirmAction(null)}
title={
confirmAction?.type === 'DELETE_USER' ? t('delete_user_confirm_title', lang) :
confirmAction?.type === 'BLOCK_USER' ? t('block_confirm_title', lang) :
t('unblock_confirm_title', lang)
}
>
<div className="space-y-4">
<p className="text-on-surface-variant">
{
confirmAction?.type === 'DELETE_USER' ? t('delete_user_confirm_msg', lang) :
confirmAction?.type === 'BLOCK_USER' ? t('block_confirm_msg', lang) :
t('unblock_confirm_msg', lang)
}
</p>
{confirmAction?.email && (
<p className="font-medium text-on-surface">{confirmAction.email}</p>
)}
<div className="flex justify-end gap-2 mt-4">
<Button onClick={() => setConfirmAction(null)} variant="ghost">
{t('cancel', lang)}
</Button>
<Button
onClick={handleConfirmAction}
variant={confirmAction?.type === 'UNBLOCK_USER' ? 'primary' : 'destructive'}
>
{t('confirm', lang)}
</Button>
</div>
</div>
</Modal>
</div>
<Snackbar
isOpen={snackbar.isOpen}