admin user able to create test txs
This commit is contained in:
@@ -125,36 +125,59 @@ class _AccountScreenState extends State<AccountScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (auth.isAdmin) ...[
|
||||
const SizedBox(height: 16),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.add_card_outlined),
|
||||
title: const Text('Create test transaction'),
|
||||
subtitle: const Text(
|
||||
'Admin only · local + syncs to PocketBase',
|
||||
),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
final tx = await showAdminCreateTransactionDialog(context);
|
||||
if (tx == null || !context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Created “${tx.description}” · '
|
||||
'${tx.amount.toStringAsFixed(2)} ${tx.currency}',
|
||||
),
|
||||
),
|
||||
);
|
||||
// Push so other devices / PB see it soon.
|
||||
final sync = context.read<SyncController>();
|
||||
if (sync.canSync && !sync.isSyncing) {
|
||||
unawaited(sync.syncNow());
|
||||
}
|
||||
},
|
||||
const SizedBox(height: 16),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
Icons.add_card_outlined,
|
||||
color: auth.isAdmin ? null : colors.onSurfaceVariant,
|
||||
),
|
||||
title: const Text('Create test transaction'),
|
||||
subtitle: Text(
|
||||
auth.isAdmin
|
||||
? 'Admin · saved locally and synced to PocketBase'
|
||||
: 'Admin only · enable is_admin on your usersapp user in PocketBase, then sign out and back in',
|
||||
),
|
||||
trailing: auth.isAdmin
|
||||
? const Icon(Icons.chevron_right)
|
||||
: Icon(
|
||||
Icons.lock_outline,
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
onTap: () async {
|
||||
if (!auth.isAdmin) {
|
||||
await auth.refreshSession();
|
||||
if (!context.mounted) return;
|
||||
if (!context.read<AuthController>().isAdmin) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Not an admin yet. In PocketBase Admin → '
|
||||
'usersapp → your user → set is_admin = true, '
|
||||
'then sign out and sign in again.',
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final tx = await showAdminCreateTransactionDialog(context);
|
||||
if (tx == null || !context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Created “${tx.description}” · '
|
||||
'${tx.amount.toStringAsFixed(2)} ${tx.currency}',
|
||||
),
|
||||
),
|
||||
);
|
||||
final sync = context.read<SyncController>();
|
||||
if (sync.canSync && !sync.isSyncing) {
|
||||
unawaited(sync.syncNow());
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Card(
|
||||
child: ListTile(
|
||||
|
||||
Reference in New Issue
Block a user