UI fixes for new groups, form validation for discussion topic

pull/1428/head
ggurdin 1 year ago
parent 689252c17f
commit 3a6d6de7c5
No known key found for this signature in database
GPG Key ID: A01CB41737CBB478

@ -4359,5 +4359,6 @@
"enterPrompt": "Please enter a system prompt",
"selectBotLanguage": "Select bot language",
"chooseVoice": "Choose a voice",
"enterLanguageLevel": "Please enter a language level"
"enterLanguageLevel": "Please enter a language level",
"enterDiscussionTopic": "Please enter a discussion topic"
}

@ -106,6 +106,20 @@ class NewGroupController extends State<NewGroup> {
// #Pangea
// validate init bot options
if (addConversationBotKey.currentState?.formKey.currentState != null) {
final isValid = addConversationBotKey
.currentState!.formKey.currentState!
.validate();
if (isValid == false) {
setState(() {
error = L10n.of(context)!
.conversationBotCustomZone_customSystemPromptEmptyError;
loading = false;
});
return;
}
}
addConversationBotKey.currentState?.updateAllBotOptions();
final addBot = addConversationBotKey.currentState?.addBot ?? false;
if (addBot) {
final botOptions = addConversationBotKey.currentState!.botOptions;

@ -29,6 +29,9 @@ class ConversationBotModeDynamicZone extends StatelessWidget {
.conversationBotDiscussionZone_discussionTopicPlaceholder,
),
controller: discussionTopicController,
validator: (value) => value == null || value.isEmpty
? L10n.of(context)!.enterDiscussionTopic
: null,
),
const SizedBox(height: 12),
TextFormField(

@ -99,6 +99,12 @@ class ConversationBotSettingsState extends State<ConversationBotSettings> {
);
}
void updateAllBotOptions() {
botOptions.discussionTopic = discussionTopicController.text;
botOptions.discussionKeywords = discussionKeywordsController.text;
botOptions.customSystemPrompt = customSystemPromptController.text;
}
Future<void> showBotOptionsDialog() async {
if (isCreating) return;
final bool? confirm = await showDialog<bool>(
@ -135,10 +141,7 @@ class ConversationBotSettingsState extends State<ConversationBotSettings> {
);
if (confirm == true) {
botOptions.discussionTopic = discussionTopicController.text;
botOptions.discussionKeywords = discussionKeywordsController.text;
botOptions.customSystemPrompt = customSystemPromptController.text;
updateAllBotOptions();
updateBotOption(() => botOptions = botOptions);
final bool isBotRoomMember = await widget.room?.botIsInRoom ?? false;
@ -241,12 +244,34 @@ class ConversationBotSettingsState extends State<ConversationBotSettings> {
onTap: showBotOptionsDialog,
),
if (isCreating && addBot)
ConversationBotSettingsForm(
botOptions: botOptions,
formKey: formKey,
discussionKeywordsController: discussionKeywordsController,
discussionTopicController: discussionTopicController,
customSystemPromptController: customSystemPromptController,
Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Text(
L10n.of(context)!.botConfig,
style: Theme.of(context).textTheme.titleLarge,
),
),
),
Form(
key: formKey,
child: ConversationBotSettingsForm(
botOptions: botOptions,
formKey: formKey,
discussionKeywordsController:
discussionKeywordsController,
discussionTopicController: discussionTopicController,
customSystemPromptController:
customSystemPromptController,
),
),
],
),
),
],
),

@ -95,7 +95,7 @@ class ConversationBotSettingsFormState
validator: (value) =>
value == null ? L10n.of(context)!.enterLanguageLevel : null,
),
const SizedBox(height: 20),
const SizedBox(height: 12),
Align(
alignment: Alignment.centerLeft,
child: Padding(
@ -106,7 +106,6 @@ class ConversationBotSettingsFormState
),
),
),
const SizedBox(height: 12),
ConversationBotModeSelect(
initialMode: botOptions.mode,
onChanged: (String? mode) => {

Loading…
Cancel
Save