Delete publisher

This commit is contained in:
LittleSheep 2025-02-15 18:43:06 +08:00
parent c91cf7c813
commit 43e3404dbb
4 changed files with 47 additions and 4 deletions

View File

@ -15,7 +15,7 @@ body:json {
"client_id": "alphabot", "client_id": "alphabot",
"client_secret": "_uR0sVnHTh", "client_secret": "_uR0sVnHTh",
"remark": "新年红包", "remark": "新年红包",
"amount": 9705, "amount": 150,
"payee_id": 2 "payee_id": 18
} }
} }

View File

@ -638,5 +638,7 @@
"pollVotes": { "pollVotes": {
"one": "{} vote", "one": "{} vote",
"other": "{} votes" "other": "{} votes"
} },
"publisherDelete": "Delete Publisher {}",
"publisherDeleteDescription": "Are you sure you want to delete this publisher? This operation is irreversible."
} }

View File

@ -637,5 +637,7 @@
"pollVotes": { "pollVotes": {
"one": "{} 票", "one": "{} 票",
"other": "{} 票" "other": "{} 票"
} },
"publisherDelete": "删除发布者 {}",
"publisherDeleteDescription": "你确定要删除这个发布者吗?该操作不可撤销。"
} }

View File

@ -45,6 +45,33 @@ class _PublisherScreenState extends State<PublisherScreen> {
} }
} }
Future<void> _deletePublisher(SnPublisher publisher) async {
final confirm = await context.showConfirmDialog(
'publisherDelete'.tr(args: ['#${publisher.name}']),
'publisherDeleteDescription'.tr(),
);
if (!confirm) return;
if (!mounted) return;
setState(() => _isBusy = true);
try {
await context
.read<SnNetworkProvider>()
.client
.delete('/cgi/co/publishers/${publisher.name}');
if (!mounted) return;
context.showSnackbar('publisherDeleted'.tr(args: ['#${publisher.name}']));
_publishers.remove(publisher);
_fetchPublishers();
} catch (err) {
if (!mounted) return;
context.showErrorDialog(err);
} finally {
setState(() => _isBusy = false);
}
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -118,6 +145,18 @@ class _PublisherScreenState extends State<PublisherScreen> {
}); });
}, },
), ),
PopupMenuItem(
child: Row(
children: [
const Icon(Symbols.delete),
const Gap(16),
Text('delete').tr(),
],
),
onTap: () {
_deletePublisher(publisher);
},
),
], ],
), ),
); );