diff --git a/src/modules/cmdpal/extensions/SamplePagesExtension/Forms/SampleForm.cs b/src/modules/cmdpal/extensions/SamplePagesExtension/Forms/SampleForm.cs new file mode 100644 index 0000000000..b0c766e3cb --- /dev/null +++ b/src/modules/cmdpal/extensions/SamplePagesExtension/Forms/SampleForm.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.IO; +using System.Text.Json.Nodes; +using Microsoft.CmdPal.Extensions; +using Microsoft.CmdPal.Extensions.Helpers; + +namespace SamplePagesExtension; + +internal sealed class SampleForm : Form +{ + public override string TemplateJson() + { + var json = $$""" +{ + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "type": "AdaptiveCard", + "version": "1.5", + "body": [ + { + "type": "Input.Text", + "style": "text", + "id": "text1", + "label": "Input.Text", + "isRequired": true, + "errorMessage": "Text is required" + } + ], + "actions": [ + { + "type": "Action.Submit", + "title": "Action.Submit", + "data": { + "text1": "text1", + } + } + ] +} +"""; + return json; + } + + public override string DataJson() => throw new NotImplementedException(); + + public override string StateJson() => throw new NotImplementedException(); + + public override ActionResult SubmitForm(string payload) + { + var formInput = JsonNode.Parse(payload); + if (formInput == null) + { + return ActionResult.GoHome(); + } + + // get the name and url out of the values + + // var testInput = formInput["test1"] ?? string.Empty; + return ActionResult.GoHome(); + } +} diff --git a/src/modules/cmdpal/extensions/SamplePagesExtension/Pages/SampleFormPage.cs b/src/modules/cmdpal/extensions/SamplePagesExtension/Pages/SampleFormPage.cs new file mode 100644 index 0000000000..111f6c43c3 --- /dev/null +++ b/src/modules/cmdpal/extensions/SamplePagesExtension/Pages/SampleFormPage.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.CmdPal.Extensions; +using Microsoft.CmdPal.Extensions.Helpers; + +namespace SamplePagesExtension; + +internal sealed class SampleFormPage : FormPage +{ + private readonly SampleForm sampleForm = new(); + + public override IForm[] Forms() => [sampleForm]; + + public SampleFormPage() + { + Name = "Sample Form"; + Icon = new(string.Empty); + } +} diff --git a/src/modules/cmdpal/extensions/SamplePagesExtension/SamplePagesCommandsProvider.cs b/src/modules/cmdpal/extensions/SamplePagesExtension/SamplePagesCommandsProvider.cs index e364cc88bf..90115e95ba 100644 --- a/src/modules/cmdpal/extensions/SamplePagesExtension/SamplePagesCommandsProvider.cs +++ b/src/modules/cmdpal/extensions/SamplePagesExtension/SamplePagesCommandsProvider.cs @@ -26,6 +26,11 @@ public class SamplePagesCommandsProvider : ICommandProvider Title = "List Page Sample Command", Subtitle = "SamplePages Extension", }, + new ListItem(new SampleListPage()) + { + Title = "Form Page Sample Command", + Subtitle = "SamplePages Extension", + } ]; #pragma warning disable CA1816 // Dispose methods should call SuppressFinalize