fdds
This commit is contained in:
@@ -5,6 +5,8 @@ import 'package:flux/features/company/models/company_model.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/master_data/store/models/store_model.dart';
|
||||
import 'package:flux/features/onboarding/blocs/onboarding_state.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class OnboardingCubit extends Cubit<OnboardingState> {
|
||||
final CoreRepository _repository;
|
||||
@@ -14,8 +16,15 @@ class OnboardingCubit extends Cubit<OnboardingState> {
|
||||
: super(OnboardingState(step: _sessionCubit.state.onboardingStep));
|
||||
|
||||
// --- STEP 1: REGISTRAZIONE AZIENDA ---
|
||||
Future<void> saveCompany(CompanyModel company) async {
|
||||
Future<void> saveCompany(String companyName) async {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
final company = CompanyModel.empty().copyWith(
|
||||
ragioneSociale: companyName,
|
||||
userId: GetIt.I<SupabaseClient>().auth.currentUser!.id,
|
||||
subscriptionTier: SubscriptionTier.pro,
|
||||
subscriptionStatus: SubscriptionStatus.trialing,
|
||||
trialEndsAt: DateTime.now().add(const Duration(days: 14)),
|
||||
);
|
||||
try {
|
||||
// Il repository restituisce il modello creato con l'ID di Supabase
|
||||
final savedCompany = await _repository.createCompany(company);
|
||||
|
||||
@@ -41,7 +41,7 @@ class _CompanyOnboardingFormState extends State<CompanyOnboardingForm> {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
"Inserisci i dati della tua attività per configurare il tuo ambiente FLUX.",
|
||||
"Come si chiama la tua Azienda? \n(Potrai inserire i dati di fatturazione in seguito).",
|
||||
style: TextStyle(fontSize: 16, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
@@ -51,7 +51,6 @@ class _CompanyOnboardingFormState extends State<CompanyOnboardingForm> {
|
||||
controller: _nameCtrl,
|
||||
validator: notEmptyValidator,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
const Spacer(),
|
||||
ElevatedButton(
|
||||
@@ -63,10 +62,9 @@ class _CompanyOnboardingFormState extends State<CompanyOnboardingForm> {
|
||||
),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
final newCompany = CompanyModel.empty().copyWith(
|
||||
ragioneSociale: _nameCtrl.text.trim(),
|
||||
context.read<OnboardingCubit>().saveCompany(
|
||||
_nameCtrl.text.trim(),
|
||||
);
|
||||
context.read<OnboardingCubit>().saveCompany(newCompany);
|
||||
}
|
||||
},
|
||||
child: const Text(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/data/core_repository.dart';
|
||||
import 'package:flux/core/utils/validators.dart';
|
||||
import 'package:flux/features/company/models/company_model.dart';
|
||||
import 'package:flux/features/master_data/store/models/store_model.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/onboarding/blocs/onboarding_cubit.dart';
|
||||
@@ -11,6 +11,8 @@ import 'package:flux/features/onboarding/blocs/onboarding_cubit.dart';
|
||||
import 'package:flux/core/widgets/flux_text_field.dart';
|
||||
import 'package:flux/features/onboarding/blocs/onboarding_state.dart';
|
||||
import 'package:flux/features/onboarding/ui/company_onboarding_form.dart';
|
||||
import 'package:flux/features/onboarding/ui/store_onboarding_form.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
class OnboardingScreen extends StatefulWidget {
|
||||
const OnboardingScreen({super.key});
|
||||
@@ -24,13 +26,8 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
|
||||
|
||||
// --- CHIAVI DEI FORM (Per la validazione indipendente di ogni step) ---
|
||||
|
||||
final _storeFormKey = GlobalKey<FormState>();
|
||||
final _staffFormKey = GlobalKey<FormState>();
|
||||
|
||||
// --- CONTROLLERS: STEP 2 (Store) ---
|
||||
final _storeNameCtrl = TextEditingController();
|
||||
final _storeAddressCtrl = TextEditingController();
|
||||
|
||||
// --- CONTROLLERS: STEP 3 (Staff) ---
|
||||
final _staffFirstNameCtrl = TextEditingController();
|
||||
final _staffLastNameCtrl = TextEditingController();
|
||||
@@ -47,8 +44,6 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController.dispose();
|
||||
_storeNameCtrl.dispose();
|
||||
_storeAddressCtrl.dispose();
|
||||
_staffFirstNameCtrl.dispose();
|
||||
_staffLastNameCtrl.dispose();
|
||||
_staffJobTitleCtrl.dispose();
|
||||
@@ -118,7 +113,7 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
|
||||
const NeverScrollableScrollPhysics(), // Vietato lo swipe manuale!
|
||||
children: [
|
||||
CompanyOnboardingForm(state: state), // Step 1: Company
|
||||
_buildStoreForm(context, state),
|
||||
StoreOnboardingForm(state: state),
|
||||
_buildStaffForm(context, state),
|
||||
],
|
||||
),
|
||||
@@ -137,67 +132,6 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStoreForm(BuildContext context, OnboardingState state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(32.0),
|
||||
child: Form(
|
||||
key: _storeFormKey,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
"Il tuo Negozio 🏪",
|
||||
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
"Dove si trova il tuo punto vendita principale? (Potrai aggiungerne altri in seguito).",
|
||||
style: TextStyle(fontSize: 16, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
FluxTextField(
|
||||
label: 'Nome Negozio (es. Sede Centrale)',
|
||||
controller: _storeNameCtrl,
|
||||
validator: notEmptyValidator,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FluxTextField(
|
||||
label: 'Indirizzo completo',
|
||||
controller: _storeAddressCtrl,
|
||||
validator: notEmptyValidator,
|
||||
),
|
||||
|
||||
const Spacer(),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (_storeFormKey.currentState!.validate()) {
|
||||
final newStore = StoreModel.empty().copyWith(
|
||||
nome: _storeNameCtrl.text.trim(),
|
||||
indirizzo: _storeAddressCtrl.text.trim(),
|
||||
);
|
||||
context.read<OnboardingCubit>().saveStore(newStore);
|
||||
}
|
||||
},
|
||||
child: const Text(
|
||||
"Salva Negozio",
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStaffForm(BuildContext context, OnboardingState state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(32.0),
|
||||
|
||||
189
lib/features/onboarding/ui/store_onboarding_form.dart
Normal file
189
lib/features/onboarding/ui/store_onboarding_form.dart
Normal file
@@ -0,0 +1,189 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/widgets/flux_text_field.dart';
|
||||
import 'package:flux/features/master_data/store/models/store_model.dart';
|
||||
import 'package:flux/features/onboarding/blocs/onboarding_cubit.dart';
|
||||
import 'package:flux/features/onboarding/blocs/onboarding_state.dart';
|
||||
|
||||
class StoreOnboardingForm extends StatefulWidget {
|
||||
final OnboardingState state;
|
||||
const StoreOnboardingForm({super.key, required this.state});
|
||||
|
||||
@override
|
||||
State<StoreOnboardingForm> createState() => _StoreOnboardingFormState();
|
||||
}
|
||||
|
||||
class _StoreOnboardingFormState extends State<StoreOnboardingForm> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _nameCtrl = TextEditingController();
|
||||
final _addressCtrl = TextEditingController();
|
||||
final _cityCtrl = TextEditingController();
|
||||
final _zipCodeCtrl = TextEditingController();
|
||||
final _provinceCtrl = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameCtrl.dispose();
|
||||
_addressCtrl.dispose();
|
||||
_cityCtrl.dispose();
|
||||
_zipCodeCtrl.dispose();
|
||||
_provinceCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(32.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
"Il tuo Negozio 🏪",
|
||||
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
"Dove si trova il tuo punto vendita principale? (Potrai aggiungerne altri in seguito).",
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FluxTextField(
|
||||
controller: _nameCtrl,
|
||||
label: "Nome del Negozio",
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Il nome del negozio è obbligatorio";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FluxTextField(
|
||||
controller: _addressCtrl,
|
||||
label: "Indirizzo",
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "L'indirizzo è obbligatorio";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (constraints.maxWidth < 600) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: constraints.maxWidth,
|
||||
child: FluxTextField(
|
||||
label: 'Comune',
|
||||
controller: _cityCtrl,
|
||||
keyboardType: TextInputType.name,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: constraints.maxWidth * 0.4,
|
||||
child: FluxTextField(
|
||||
label: 'CAP',
|
||||
controller: _zipCodeCtrl,
|
||||
maxLength: 5,
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
SizedBox(
|
||||
width: constraints.maxWidth * 0.2,
|
||||
child: FluxTextField(
|
||||
label: 'Prov.',
|
||||
controller: _provinceCtrl,
|
||||
keyboardType: TextInputType.text,
|
||||
onChanged: (value) =>
|
||||
_provinceCtrl.text = value.toUpperCase(),
|
||||
maxLength: 2,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 160,
|
||||
child: FluxTextField(
|
||||
label: 'CAP',
|
||||
controller: _zipCodeCtrl,
|
||||
maxLength: 5,
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
width: constraints.maxWidth * 0.5,
|
||||
child: FluxTextField(
|
||||
label: 'Comune',
|
||||
controller: _cityCtrl,
|
||||
keyboardType: TextInputType.name,
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: FluxTextField(
|
||||
label: 'Prov.',
|
||||
controller: _provinceCtrl,
|
||||
keyboardType: TextInputType.text,
|
||||
onChanged: (value) =>
|
||||
_provinceCtrl.text = value.toUpperCase(),
|
||||
maxLength: 2,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const Spacer(),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
final newStore = StoreModel.empty().copyWith(
|
||||
nome: _nameCtrl.text.trim(),
|
||||
indirizzo: _addressCtrl.text.trim(),
|
||||
comune: _cityCtrl.text.trim(),
|
||||
cap: _zipCodeCtrl.text.trim(),
|
||||
provincia: _provinceCtrl.text.trim(),
|
||||
);
|
||||
context.read<OnboardingCubit>().saveStore(newStore);
|
||||
}
|
||||
},
|
||||
child: const Text(
|
||||
"Salva Negozio",
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user