214 lines
7.3 KiB
Dart
214 lines
7.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:salonbooking/karyawan/bookings_karyawan_page.dart';
|
|
import 'package:salonbooking/karyawan/riwayat_bookings_karyawan.dart';
|
|
import 'package:salonbooking/main.dart';
|
|
import 'package:salonbooking/pemilik/home_pemilik.dart';
|
|
import 'package:salonbooking/pelanggan/main_navigation.dart';
|
|
|
|
class KaryawanHomePage extends StatelessWidget {
|
|
final String name;
|
|
final String token;
|
|
final Map user;
|
|
|
|
const KaryawanHomePage(this.name, {Key? key, required this.token, required this.user}) : super(key: key);
|
|
|
|
void logout(BuildContext context) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.remove('token');
|
|
|
|
Navigator.pushAndRemoveUntil(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => HomeSelector(
|
|
onLoginSuccess: (token, user) {
|
|
final navigator = navigatorKey.currentState!;
|
|
switch (user['role']) {
|
|
case 'pelanggan':
|
|
navigator.pushAndRemoveUntil(
|
|
MaterialPageRoute(
|
|
builder: (_) => MainNavigation(
|
|
userName: user['name'] ?? 'User',
|
|
token: token,
|
|
user: user,
|
|
),
|
|
),
|
|
(route) => false,
|
|
);
|
|
break;
|
|
case 'karyawan':
|
|
navigator.pushAndRemoveUntil(
|
|
MaterialPageRoute(
|
|
builder: (_) => KaryawanHomePage(
|
|
user['name'] ?? 'User',
|
|
token: token,
|
|
user: user,
|
|
),
|
|
),
|
|
(route) => false,
|
|
);
|
|
break;
|
|
case 'pemilik':
|
|
navigator.pushAndRemoveUntil(
|
|
MaterialPageRoute(
|
|
builder: (_) => PemilikHomePage(
|
|
name: user['name'] ?? 'User',
|
|
token: token,
|
|
),
|
|
),
|
|
(route) => false,
|
|
);
|
|
break;
|
|
default:
|
|
navigator.pushAndRemoveUntil(
|
|
MaterialPageRoute(
|
|
builder: (_) => const Scaffold(
|
|
body: Center(child: Text('Role tidak dikenal')),
|
|
),
|
|
),
|
|
(route) => false,
|
|
);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
(route) => false,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final primaryColor = const Color(0xFFF06292);
|
|
final backgroundColor = const Color(0xFFFFF0F5);
|
|
|
|
return Scaffold(
|
|
backgroundColor: backgroundColor,
|
|
appBar: AppBar(
|
|
title: const Text('Home Karyawan'),
|
|
backgroundColor: primaryColor,
|
|
elevation: 5,
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.logout),
|
|
onPressed: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Konfirmasi Logout'),
|
|
content: const Text('Apakah Anda yakin ingin logout?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Batal'),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
logout(context);
|
|
},
|
|
child: const Text(
|
|
'Logout',
|
|
style: TextStyle(color: Colors.red),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 36),
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
'Selamat datang, $name',
|
|
style: TextStyle(
|
|
fontSize: 26,
|
|
fontWeight: FontWeight.bold,
|
|
color: primaryColor,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'(Karyawan)',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
color: primaryColor.withOpacity(0.7),
|
|
fontStyle: FontStyle.italic,
|
|
),
|
|
),
|
|
const SizedBox(height: 40),
|
|
Card(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
elevation: 6,
|
|
shadowColor: primaryColor.withOpacity(0.3),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton.icon(
|
|
icon: const Icon(Icons.list, size: 28),
|
|
label: const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 14),
|
|
child: Text(
|
|
'Lihat Daftar Booking Pelanggan',
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: primaryColor,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => BookingsKaryawanPage(token: token),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Card(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
elevation: 6,
|
|
shadowColor: primaryColor.withOpacity(0.3),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton.icon(
|
|
icon: const Icon(Icons.history, size: 28),
|
|
label: const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 14),
|
|
child: Text(
|
|
'Riwayat Booking',
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: primaryColor,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => RiwayatBookingsKaryawanPage(token: token),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|