Set Password
This commit is contained in:
parent
8e35582f93
commit
2e00207343
@ -161,12 +161,18 @@ class AuthRemoteDataProvider {
|
|||||||
|
|
||||||
if (response.data['success'] == false) {
|
if (response.data['success'] == false) {
|
||||||
if ((response.data['errors'] as List).isNotEmpty) {
|
if ((response.data['errors'] as List).isNotEmpty) {
|
||||||
if (response.data['errors'][0]['code'] == "900") {
|
if (response.data['errors'][0]['code'] == 900) {
|
||||||
return DC.error(
|
return DC.error(
|
||||||
AuthFailure.dynamicErrorMessage(
|
AuthFailure.dynamicErrorMessage(
|
||||||
'Invalid Registration, Lakukan kembali dari awal',
|
'Invalid Registration, Lakukan kembali dari awal',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} else if (response.data['errors'][0]['code'] == "304") {
|
||||||
|
return DC.error(
|
||||||
|
AuthFailure.dynamicErrorMessage(
|
||||||
|
response.data['errors'][0]['cause'],
|
||||||
|
),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return DC.error(
|
return DC.error(
|
||||||
AuthFailure.dynamicErrorMessage(
|
AuthFailure.dynamicErrorMessage(
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class AppFlushbar {
|
|||||||
),
|
),
|
||||||
icon: const Icon(Icons.check_circle, color: Colors.white),
|
icon: const Icon(Icons.check_circle, color: Colors.white),
|
||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
flushbarPosition: FlushbarPosition.BOTTOM,
|
flushbarPosition: FlushbarPosition.TOP,
|
||||||
backgroundColor: AppColor.secondary,
|
backgroundColor: AppColor.secondary,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
margin: const EdgeInsets.all(12),
|
margin: const EdgeInsets.all(12),
|
||||||
@ -35,7 +35,7 @@ class AppFlushbar {
|
|||||||
),
|
),
|
||||||
icon: const Icon(Icons.error, color: Colors.white),
|
icon: const Icon(Icons.error, color: Colors.white),
|
||||||
duration: const Duration(seconds: 3),
|
duration: const Duration(seconds: 3),
|
||||||
flushbarPosition: FlushbarPosition.BOTTOM,
|
flushbarPosition: FlushbarPosition.TOP,
|
||||||
backgroundColor: AppColor.error,
|
backgroundColor: AppColor.error,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
margin: const EdgeInsets.all(12),
|
margin: const EdgeInsets.all(12),
|
||||||
|
|||||||
@ -1,19 +1,47 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
|
import '../../../../application/auth/set_password/set_password_form_bloc.dart';
|
||||||
|
import '../../../../injection.dart';
|
||||||
import '../../../components/button/button.dart';
|
import '../../../components/button/button.dart';
|
||||||
import '../../../components/field/field.dart';
|
import '../../../components/field/field.dart';
|
||||||
|
import '../../../components/toast/flushbar.dart';
|
||||||
import '../../../router/app_router.gr.dart';
|
import '../../../router/app_router.gr.dart';
|
||||||
|
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class CreatePasswordPage extends StatelessWidget {
|
class CreatePasswordPage extends StatelessWidget implements AutoRouteWrapper {
|
||||||
const CreatePasswordPage({super.key});
|
final String registrationToken;
|
||||||
|
const CreatePasswordPage({super.key, required this.registrationToken});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return BlocListener<SetPasswordFormBloc, SetPasswordFormState>(
|
||||||
|
listenWhen: (p, c) =>
|
||||||
|
p.failureOrSetPasswordOption != c.failureOrSetPasswordOption,
|
||||||
|
listener: (context, state) {
|
||||||
|
state.failureOrSetPasswordOption.fold(
|
||||||
|
() => null,
|
||||||
|
(either) => either.fold(
|
||||||
|
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
||||||
|
(data) {
|
||||||
|
AppFlushbar.showSuccess(context, data.message);
|
||||||
|
Future.delayed(Duration(milliseconds: 1000), () {
|
||||||
|
context.router.replaceAll([MainRoute()]);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Scaffold(
|
||||||
appBar: AppBar(title: const Text('Buat Kata Sandi')),
|
appBar: AppBar(title: const Text('Buat Kata Sandi')),
|
||||||
body: Padding(
|
body: BlocBuilder<SetPasswordFormBloc, SetPasswordFormState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return Form(
|
||||||
|
autovalidateMode: state.showErrorMessages
|
||||||
|
? AutovalidateMode.always
|
||||||
|
: AutovalidateMode.disabled,
|
||||||
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@ -24,11 +52,51 @@ class CreatePasswordPage extends StatelessWidget {
|
|||||||
AppPasswordTextFormField(
|
AppPasswordTextFormField(
|
||||||
title: 'Masukkan kata sandi',
|
title: 'Masukkan kata sandi',
|
||||||
hintText: '********',
|
hintText: '********',
|
||||||
|
onChanged: (value) => context
|
||||||
|
.read<SetPasswordFormBloc>()
|
||||||
|
.add(SetPasswordFormEvent.passwordChanged(value)),
|
||||||
|
validator: (value) {
|
||||||
|
if (context
|
||||||
|
.read<SetPasswordFormBloc>()
|
||||||
|
.state
|
||||||
|
.password
|
||||||
|
.isEmpty) {
|
||||||
|
return 'Masukkan kata sandi';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
),
|
),
|
||||||
SizedBox(height: 24),
|
SizedBox(height: 24),
|
||||||
AppPasswordTextFormField(
|
AppPasswordTextFormField(
|
||||||
title: 'Ulangi kata sandi',
|
title: 'Ulangi kata sandi',
|
||||||
hintText: '********',
|
hintText: '********',
|
||||||
|
onChanged: (value) =>
|
||||||
|
context.read<SetPasswordFormBloc>().add(
|
||||||
|
SetPasswordFormEvent.confirmPasswordChanged(value),
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (context
|
||||||
|
.read<SetPasswordFormBloc>()
|
||||||
|
.state
|
||||||
|
.password
|
||||||
|
.isEmpty) {
|
||||||
|
return 'Masukkan kata sandi';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context
|
||||||
|
.read<SetPasswordFormBloc>()
|
||||||
|
.state
|
||||||
|
.password !=
|
||||||
|
context
|
||||||
|
.read<SetPasswordFormBloc>()
|
||||||
|
.state
|
||||||
|
.confirmPassword) {
|
||||||
|
return 'Kata sandi tidak cocok';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 50),
|
const SizedBox(height: 50),
|
||||||
@ -37,8 +105,13 @@ class CreatePasswordPage extends StatelessWidget {
|
|||||||
|
|
||||||
// Continue Button
|
// Continue Button
|
||||||
AppElevatedButton(
|
AppElevatedButton(
|
||||||
onPressed: () => context.router.push(const MainRoute()),
|
onPressed: state.isSubmitting
|
||||||
|
? null
|
||||||
|
: () => context.read<SetPasswordFormBloc>().add(
|
||||||
|
SetPasswordFormEvent.submitted(),
|
||||||
|
),
|
||||||
title: 'Konfirmasi',
|
title: 'Konfirmasi',
|
||||||
|
isLoading: state.isSubmitting,
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
@ -46,5 +119,16 @@ class CreatePasswordPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
||||||
|
create: (context) => getIt<SetPasswordFormBloc>()
|
||||||
|
..add(SetPasswordFormEvent.registrationTokenChanged(registrationToken)),
|
||||||
|
child: this,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -143,10 +143,21 @@ class _OtpPageState extends State<OtpPage> {
|
|||||||
(either) => either.fold(
|
(either) => either.fold(
|
||||||
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
||||||
(data) {
|
(data) {
|
||||||
|
if (data.status == "FAILED") {
|
||||||
AppFlushbar.showSuccess(context, data.message);
|
AppFlushbar.showSuccess(context, data.message);
|
||||||
Future.delayed(Duration(milliseconds: 1000), () {
|
Future.delayed(Duration(milliseconds: 1000), () {
|
||||||
context.router.push(CreatePasswordRoute());
|
context.router.replaceAll([LoginRoute()]);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
AppFlushbar.showSuccess(context, data.message);
|
||||||
|
Future.delayed(Duration(milliseconds: 1000), () {
|
||||||
|
context.router.push(
|
||||||
|
CreatePasswordRoute(
|
||||||
|
registrationToken: widget.registrationToken,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -102,20 +102,49 @@ class AddressRoute extends _i33.PageRouteInfo<void> {
|
|||||||
|
|
||||||
/// generated route for
|
/// generated route for
|
||||||
/// [_i3.CreatePasswordPage]
|
/// [_i3.CreatePasswordPage]
|
||||||
class CreatePasswordRoute extends _i33.PageRouteInfo<void> {
|
class CreatePasswordRoute extends _i33.PageRouteInfo<CreatePasswordRouteArgs> {
|
||||||
const CreatePasswordRoute({List<_i33.PageRouteInfo>? children})
|
CreatePasswordRoute({
|
||||||
: super(CreatePasswordRoute.name, initialChildren: children);
|
_i34.Key? key,
|
||||||
|
required String registrationToken,
|
||||||
|
List<_i33.PageRouteInfo>? children,
|
||||||
|
}) : super(
|
||||||
|
CreatePasswordRoute.name,
|
||||||
|
args: CreatePasswordRouteArgs(
|
||||||
|
key: key,
|
||||||
|
registrationToken: registrationToken,
|
||||||
|
),
|
||||||
|
initialChildren: children,
|
||||||
|
);
|
||||||
|
|
||||||
static const String name = 'CreatePasswordRoute';
|
static const String name = 'CreatePasswordRoute';
|
||||||
|
|
||||||
static _i33.PageInfo page = _i33.PageInfo(
|
static _i33.PageInfo page = _i33.PageInfo(
|
||||||
name,
|
name,
|
||||||
builder: (data) {
|
builder: (data) {
|
||||||
return const _i3.CreatePasswordPage();
|
final args = data.argsAs<CreatePasswordRouteArgs>();
|
||||||
|
return _i33.WrappedRoute(
|
||||||
|
child: _i3.CreatePasswordPage(
|
||||||
|
key: args.key,
|
||||||
|
registrationToken: args.registrationToken,
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CreatePasswordRouteArgs {
|
||||||
|
const CreatePasswordRouteArgs({this.key, required this.registrationToken});
|
||||||
|
|
||||||
|
final _i34.Key? key;
|
||||||
|
|
||||||
|
final String registrationToken;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'CreatePasswordRouteArgs{key: $key, registrationToken: $registrationToken}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// generated route for
|
/// generated route for
|
||||||
/// [_i4.DrawDetailPage]
|
/// [_i4.DrawDetailPage]
|
||||||
class DrawDetailRoute extends _i33.PageRouteInfo<void> {
|
class DrawDetailRoute extends _i33.PageRouteInfo<void> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user