apk
This commit is contained in:
parent
764ac1bb82
commit
a348a0ac65
3 changed files with 170 additions and 148 deletions
Binary file not shown.
|
|
@ -1,6 +1,8 @@
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import 'package:mnemo_cards/admin/admin_api.dart';
|
import 'package:mnemo_cards/admin/admin_api.dart';
|
||||||
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
||||||
|
|
@ -57,6 +59,22 @@ class AddPromocodeCampaign {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> _loadCampaign(String id) async {
|
||||||
|
try {
|
||||||
|
final campaign = await adminApi.getPromoCodeCampaign(id);
|
||||||
|
if (campaign != null) {
|
||||||
|
_campaigns.removeWhere((v) => v.id.toString() == id);
|
||||||
|
_campaigns.add(campaign);
|
||||||
|
campaignDto = campaign;
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
log('Error', error: e, stackTrace: s);
|
||||||
|
print('Error $e');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void _savePromoCodeCampaign() async {
|
void _savePromoCodeCampaign() async {
|
||||||
final result = await adminApi.addPromoCodeCampaign(campaignDto);
|
final result = await adminApi.addPromoCodeCampaign(campaignDto);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|
@ -105,6 +123,8 @@ class AddPromocodeCampaign {
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
body: Material(
|
body: Material(
|
||||||
child: StatefulBuilder(builder: (context, setCampaign) {
|
child: StatefulBuilder(builder: (context, setCampaign) {
|
||||||
|
final codes = campaignDto.promoCodes;
|
||||||
|
|
||||||
return ListView(
|
return ListView(
|
||||||
children: [
|
children: [
|
||||||
Header(
|
Header(
|
||||||
|
|
@ -112,13 +132,16 @@ class AddPromocodeCampaign {
|
||||||
hasPopButton: true,
|
hasPopButton: true,
|
||||||
trail: Row(
|
trail: Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
if (campaignDto.id != null)
|
||||||
onPressed: () async {
|
IconButton(
|
||||||
await _loadCampaigns();
|
onPressed: () async {
|
||||||
setCampaign(() {});
|
await _loadCampaign(
|
||||||
},
|
campaignDto.id.toString(),
|
||||||
icon: Icon(Icons.sync),
|
);
|
||||||
),
|
setCampaign(() {});
|
||||||
|
},
|
||||||
|
icon: Icon(Icons.note),
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: _savePromoCodeCampaign,
|
onPressed: _savePromoCodeCampaign,
|
||||||
icon: Icon(Icons.save),
|
icon: Icon(Icons.save),
|
||||||
|
|
@ -158,7 +181,7 @@ class AddPromocodeCampaign {
|
||||||
value: campaign?.id,
|
value: campaign?.id,
|
||||||
label: campaign == null
|
label: campaign == null
|
||||||
? 'New'
|
? 'New'
|
||||||
: '${campaign.name ?? campaign.promoCodes?.firstOrNull ?? campaign.id} ${campaign.status.name}',
|
: '${campaign.name ??campaign.id} ${campaign.status.name}',
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
|
|
@ -166,147 +189,142 @@ class AddPromocodeCampaign {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.all(8.0),
|
padding: EdgeInsets.all(8.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
children: [
|
||||||
Column(
|
TextParam(
|
||||||
children: [
|
'Name',
|
||||||
TextParam(
|
campaignDto.name,
|
||||||
'Name',
|
(v) {
|
||||||
campaignDto.name,
|
campaignDto = campaignDto.copyWith(
|
||||||
(v) {
|
name: v,
|
||||||
campaignDto = campaignDto.copyWith(
|
);
|
||||||
name: v,
|
},
|
||||||
|
),
|
||||||
|
TextParam(
|
||||||
|
'Template',
|
||||||
|
campaignDto.template,
|
||||||
|
(v) {
|
||||||
|
campaignDto = campaignDto.copyWith(
|
||||||
|
template: v,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
r'$d - digit $l - letter $s - any',
|
||||||
|
),
|
||||||
|
IntParam(
|
||||||
|
'Generation size',
|
||||||
|
campaignDto.generationSize,
|
||||||
|
(v) {
|
||||||
|
campaignDto = campaignDto.copyWith(
|
||||||
|
generationSize: v);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
IntParam(
|
||||||
|
'Activations per code',
|
||||||
|
campaignDto.activationsPerCode,
|
||||||
|
(v) {
|
||||||
|
campaignDto = campaignDto.copyWith(
|
||||||
|
activationsPerCode: v,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
DateParam(
|
||||||
|
'Start',
|
||||||
|
campaignDto.start,
|
||||||
|
(v) {
|
||||||
|
setState(() {
|
||||||
|
campaignDto =
|
||||||
|
campaignDto.copyWith(start: v);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
DateParam(
|
||||||
|
'Finish',
|
||||||
|
campaignDto.finish,
|
||||||
|
(v) {
|
||||||
|
setState(() {
|
||||||
|
campaignDto =
|
||||||
|
campaignDto.copyWith(finish: v);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
EnumParam(
|
||||||
|
'Status',
|
||||||
|
PromoCodeCampaignStatus.values,
|
||||||
|
campaignDto.status, (v) {
|
||||||
|
setState(() {
|
||||||
|
campaignDto =
|
||||||
|
campaignDto.copyWith(status: v);
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
Text(
|
||||||
|
'Created to generate promocodes\n'
|
||||||
|
'Disabled to disable\n'
|
||||||
|
'Dont use other statuses!',
|
||||||
|
style: TextStyle(fontSize: 12),
|
||||||
|
),
|
||||||
|
Text('Products:'),
|
||||||
|
ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount:
|
||||||
|
campaignDto.products.length + 1,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if (index ==
|
||||||
|
campaignDto.products.length) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text('Add'),
|
||||||
|
onTap: () async {
|
||||||
|
final p =
|
||||||
|
await _showProductDialog(
|
||||||
|
context, null);
|
||||||
|
if (p != null) {
|
||||||
|
setState(() {
|
||||||
|
campaignDto.products.add(p);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final item =
|
||||||
|
campaignDto.products[index];
|
||||||
|
return ListTile(
|
||||||
|
title: Text(
|
||||||
|
'${item.type.name} ${item.id ?? ''}'),
|
||||||
|
onTap: () async {
|
||||||
|
final p = await _showProductDialog(
|
||||||
|
context,
|
||||||
|
item,
|
||||||
);
|
);
|
||||||
},
|
if (p != null) {
|
||||||
),
|
setState(() {
|
||||||
TextParam(
|
campaignDto.products.add(p);
|
||||||
'Template',
|
});
|
||||||
campaignDto.template,
|
|
||||||
(v) {
|
|
||||||
campaignDto = campaignDto.copyWith(
|
|
||||||
template: v,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
description:
|
|
||||||
r'$d - digit $l - letter $s - any',
|
|
||||||
),
|
|
||||||
IntParam(
|
|
||||||
'Generation size',
|
|
||||||
campaignDto.generationSize,
|
|
||||||
(v) {
|
|
||||||
campaignDto = campaignDto.copyWith(
|
|
||||||
generationSize: v);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IntParam(
|
|
||||||
'Activations per code',
|
|
||||||
campaignDto.activationsPerCode,
|
|
||||||
(v) {
|
|
||||||
campaignDto = campaignDto.copyWith(
|
|
||||||
activationsPerCode: v,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
DateParam(
|
|
||||||
'Start',
|
|
||||||
campaignDto.start,
|
|
||||||
(v) {
|
|
||||||
setState(() {
|
|
||||||
campaignDto = campaignDto
|
|
||||||
.copyWith(start: v);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
DateParam(
|
|
||||||
'Finish',
|
|
||||||
campaignDto.finish,
|
|
||||||
(v) {
|
|
||||||
setState(() {
|
|
||||||
campaignDto = campaignDto
|
|
||||||
.copyWith(finish: v);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
DateParam(
|
|
||||||
'Finish',
|
|
||||||
campaignDto.finish,
|
|
||||||
(v) {
|
|
||||||
setState(() {
|
|
||||||
campaignDto = campaignDto
|
|
||||||
.copyWith(finish: v);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
EnumParam(
|
|
||||||
'Status',
|
|
||||||
PromoCodeCampaignStatus.values,
|
|
||||||
campaignDto.status, (v) {
|
|
||||||
setState(() {
|
|
||||||
campaignDto =
|
|
||||||
campaignDto.copyWith(status: v);
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
Text(
|
|
||||||
'Created to generate promocodes\n'
|
|
||||||
'Disabled to disable\n'
|
|
||||||
'Dont use other statuses!',
|
|
||||||
style: TextStyle(fontSize: 12),
|
|
||||||
),
|
|
||||||
Text('Products:'),
|
|
||||||
ListView.builder(
|
|
||||||
shrinkWrap: true,
|
|
||||||
itemCount:
|
|
||||||
campaignDto.products.length + 1,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index ==
|
|
||||||
campaignDto.products.length) {
|
|
||||||
return ListTile(
|
|
||||||
title: Text('Add'),
|
|
||||||
onTap: () async {
|
|
||||||
final p =
|
|
||||||
await _showProductDialog(
|
|
||||||
context, null);
|
|
||||||
if (p != null) {
|
|
||||||
setState(() {
|
|
||||||
campaignDto.products
|
|
||||||
.add(p);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
final item =
|
|
||||||
campaignDto.products[index];
|
|
||||||
return ListTile(
|
|
||||||
title: Text(
|
|
||||||
'${item.type.name} ${item.id ?? ''}'),
|
|
||||||
onTap: () async {
|
|
||||||
final p =
|
|
||||||
await _showProductDialog(
|
|
||||||
context,
|
|
||||||
item,
|
|
||||||
);
|
|
||||||
if (p != null) {
|
|
||||||
setState(() {
|
|
||||||
campaignDto.products.add(p);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
trailing: IconButton(
|
|
||||||
icon: Icon(Icons.delete),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
campaignDto.products
|
|
||||||
.remove(item);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
trailing: IconButton(
|
||||||
],
|
icon: Icon(Icons.delete),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
campaignDto.products
|
||||||
|
.remove(item);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
SimpleTile.text(
|
||||||
|
text: codes == null
|
||||||
|
? 'Codes not loaded'
|
||||||
|
: 'Codes: ${codes.length == 1 ? codes.first : codes.length}',
|
||||||
|
onTap: () async {
|
||||||
|
if (codes != null) {
|
||||||
|
await Clipboard.setData(
|
||||||
|
ClipboardData(
|
||||||
|
text: codes.join('\n'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import 'dart:convert';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:mnemo_cards/di/injector.dart';
|
import 'package:mnemo_cards/di/injector.dart';
|
||||||
import 'package:mnemo_cards/features/packs/packs_api.dart';
|
import 'package:mnemo_cards/features/packs/packs_api.dart';
|
||||||
|
import 'package:mnemo_cards/features/worker/worker_ext.dart';
|
||||||
import 'package:mnemo_cards/managers/repository/api.dart';
|
import 'package:mnemo_cards/managers/repository/api.dart';
|
||||||
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
||||||
|
|
||||||
|
|
@ -153,12 +154,15 @@ class AdminApi with Api {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<PromoCodesCampaignDto>> getPromoCodeCampaigns() async {
|
Future<List<PromoCodesCampaignDto>> getPromoCodeCampaigns() async {
|
||||||
final r = await _dio.get<String>(
|
final r = await _dio.get<String>('$path/promocode/list');
|
||||||
'$path/promocode/list',
|
|
||||||
);
|
|
||||||
return (jsonDecode(r.data!)['campaigns'] as List)
|
return (jsonDecode(r.data!)['campaigns'] as List)
|
||||||
.cast<Map<String, Object?>>()
|
.cast<Map<String, Object?>>()
|
||||||
.map(PromoCodesCampaignDto.fromJson)
|
.map(PromoCodesCampaignDto.fromJson)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<PromoCodesCampaignDto?> getPromoCodeCampaign(String id) async {
|
||||||
|
final r = await _dio.get<String>('$path/promocode/$id');
|
||||||
|
return r.data?.isolatedDecode(PromoCodesCampaignDto.fromJson);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue