added sample form

This commit is contained in:
Jordi Adoumie
2024-09-07 07:51:53 -07:00
parent 4f14db8772
commit 600d039084
3 changed files with 89 additions and 0 deletions

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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