Registration: corporate culture

master
Rafael 2024-05-21 19:37:00 +02:00
parent 017cf363d4
commit 2a2a82d71d
4 changed files with 290 additions and 53 deletions

View File

@ -20,6 +20,8 @@ class Constants {
static const String dbFieldUsersSkillsSought = 'skills_sought';
static const String dbFieldUsersAvailability = 'availability';
static const String dbFieldUsersVisions = 'visions';
static const String dbFieldUsersWorkValues = 'work_values';
static const String dbFieldUsersCorpCulture = 'corp_culture';
static const String pathLanguagesJson = 'lib/assets/languages.json';
}

View File

@ -76,3 +76,43 @@ enum AvailabilityOption {
}
}
}
enum WorkValueOption {
transparency,
innovation,
teamwork,
workLifeBalance;
String get displayName {
switch (this) {
case WorkValueOption.transparency:
return 'Transparency and openness';
case WorkValueOption.innovation:
return 'Innovation and creativity';
case WorkValueOption.teamwork:
return 'Teamwork and collaboration';
case WorkValueOption.workLifeBalance:
return 'Work-life balance';
}
}
}
enum CultureOption {
performanceOriented,
supportive,
flexible,
traditional;
String get displayName {
switch (this) {
case CultureOption.performanceOriented:
return 'Performance-oriented and competitive';
case CultureOption.supportive:
return 'Supportive and collegial';
case CultureOption.flexible:
return 'Flexible and adaptable';
case CultureOption.traditional:
return 'Traditional and structured';
}
}
}

View File

@ -0,0 +1,191 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import '../constants.dart';
import '../enumerations.dart';
import '../pages/registration_complete_page.dart';
import '../services/auth/auth_service.dart';
class CultureValuesFormPage extends StatefulWidget {
const CultureValuesFormPage({super.key, required this.isRegProcess});
final bool isRegProcess;
@override
CultureValuesFormPageState createState() => CultureValuesFormPageState();
}
class CultureValuesFormPageState extends State<CultureValuesFormPage> {
Map<WorkValueOption, bool> selectedValueOptions = {
WorkValueOption.transparency: false,
WorkValueOption.innovation: false,
WorkValueOption.teamwork: false,
WorkValueOption.workLifeBalance: false,
};
CultureOption? selectedCultureOption;
final AuthService _authService = AuthService();
final int minWorkValueOption = 1;
final int maxWorkValueOption = 2;
@override
void initState() {
super.initState();
_loadDataFromFirebase();
}
Future<void> _loadDataFromFirebase() async {
final userDoc = FirebaseFirestore.instance
.collection(Constants.dbCollectionUsers)
.doc(_authService.getCurrentUser()!.uid);
final snapshot = await userDoc.get();
if (snapshot.exists) {
final data = snapshot.data();
setState(() {
// Load WorkValue options
if (data != null) {
if (data[Constants.dbFieldUsersWorkValues] != null) {
for (var option in WorkValueOption.values) {
selectedValueOptions[option] =
data[Constants.dbFieldUsersWorkValues]
.contains(option.toString());
}
}
// Load Culture option
if (data[Constants.dbFieldUsersCorpCulture] != null) {
selectedCultureOption = CultureOption.values.firstWhere(
(e) => e.toString() == data[Constants.dbFieldUsersCorpCulture],
);
}
}
});
}
}
Future<void> _saveDataToFirebase() async {
final userDoc = FirebaseFirestore.instance
.collection(Constants.dbCollectionUsers)
.doc(_authService.getCurrentUser()!.uid);
await userDoc.set(
{
Constants.dbFieldUsersWorkValues: selectedValueOptions.entries
.where((entry) => entry.value)
.map((entry) => entry.key.toString())
.toList(),
Constants.dbFieldUsersCorpCulture: selectedCultureOption?.toString(),
},
SetOptions(merge: true),
); // avoid overwriting existing data
}
bool isWorkValueSelected() {
int selectedCount =
selectedValueOptions.values.where((value) => value).length;
return selectedCount >= minWorkValueOption &&
selectedCount <= maxWorkValueOption;
}
void handleSubmit() {
if (!isWorkValueSelected()) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Please select at least ${minWorkValueOption.toString()} and at most ${maxWorkValueOption.toString()} work life values.'),
));
return;
}
if (selectedCultureOption == null) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Please select a corporate culture.'),
));
return;
}
_saveDataToFirebase();
// Handle the form submission logic here
Navigator.push(
context,
MaterialPageRoute(
//
// TODO set following registration page HERE
//
builder: (context) => const RegistrationCompletePage(),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Personal preferences'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
children: [
const Text(
'Work life and corporate culture',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const Text(
'What values are most important to you in your working environment?',
),
...WorkValueOption.values.map((option) {
return CheckboxListTile(
title: Text(option.displayName),
value: selectedValueOptions[option],
onChanged: (bool? value) {
setState(() {
int selectedCount = selectedValueOptions.values
.where((value) => value)
.length;
if (value == false ||
selectedCount < maxWorkValueOption) {
selectedValueOptions[option] = value!;
} else if (value == true &&
selectedCount >= maxWorkValueOption) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(
content: Text(
'You can only select a maximum of two values.',
),
));
}
});
},
);
}),
const SizedBox(height: 40),
const Align(
alignment: Alignment.centerLeft,
child: Text('Which corporate culture suits you best?')),
DropdownButton<CultureOption>(
hint: const Text('Choose a corporate culture'),
value: selectedCultureOption,
onChanged: (CultureOption? newValue) {
setState(() {
selectedCultureOption = newValue;
});
},
items: CultureOption.values.map((CultureOption option) {
return DropdownMenuItem<CultureOption>(
value: option,
child: Text(option.displayName),
);
}).toList(),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: handleSubmit,
child: Text(widget.isRegProcess ? 'Save and continue' : 'Save'),
),
],
),
),
),
);
}
}

View File

@ -2,7 +2,7 @@ import "package:cloud_firestore/cloud_firestore.dart";
import "package:flutter/material.dart";
import "../constants.dart";
import "../enumerations.dart";
import "registration_complete_page.dart";
import "../forms/corporate_culture_form.dart";
import "../services/auth/auth_service.dart";
class MatchingForm extends StatefulWidget {
@ -82,7 +82,7 @@ class MatchingFormState extends State<MatchingForm> {
void handleSubmit() {
if (!isVisionSelected()) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Please choose at least one long-term vision.'),
content: Text('Please select at least one long-term vision.'),
));
return;
}
@ -97,8 +97,12 @@ class MatchingFormState extends State<MatchingForm> {
Navigator.push(
context,
MaterialPageRoute(
// TODO set following registration page HERE
builder: (context) => const RegistrationCompletePage(),
//
// set following registration page HERE
//
builder: (context) => CultureValuesFormPage(
isRegProcess: widget.isRegProcess,
),
),
);
}
@ -111,6 +115,7 @@ class MatchingFormState extends State<MatchingForm> {
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -134,13 +139,10 @@ class MatchingFormState extends State<MatchingForm> {
);
}),
const SizedBox(height: 40),
const Align(
alignment: Alignment.centerLeft,
child: Text(
const Text(
'Availability and commitment',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
const Text(
'How much time can you devote to the startup each week?',
),
@ -160,12 +162,14 @@ class MatchingFormState extends State<MatchingForm> {
Center(
child: ElevatedButton(
onPressed: handleSubmit,
child: Text(widget.isRegProcess ? 'Save and continue' : 'Save'),
child:
Text(widget.isRegProcess ? 'Save and continue' : 'Save'),
),
),
],
),
),
),
);
}
}