Added sample react-graph-feedback-form (#939)
This commit is contained in:
parent
ee2c492867
commit
7866d62ec3
|
@ -0,0 +1,25 @@
|
|||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
|
||||
[*]
|
||||
|
||||
# change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# we recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{package,bower}.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1,32 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
|
||||
# Build generated files
|
||||
dist
|
||||
lib
|
||||
solution
|
||||
temp
|
||||
*.sppkg
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# OSX
|
||||
.DS_Store
|
||||
|
||||
# Visual Studio files
|
||||
.ntvs_analysis.dat
|
||||
.vs
|
||||
bin
|
||||
obj
|
||||
|
||||
# Resx Generated Code
|
||||
*.resx.ts
|
||||
|
||||
# Styles Generated Code
|
||||
*.scss.ts
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"isCreatingSolution": true,
|
||||
"environment": "spo",
|
||||
"version": "1.8.2",
|
||||
"libraryName": "react-graph-feedback-form",
|
||||
"libraryId": "8cf91ad7-be8e-4f6c-a1eb-a790f3ef5a32",
|
||||
"packageManager": "npm",
|
||||
"isDomainIsolated": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
# Feedback Form
|
||||
|
||||
## Summary
|
||||
|
||||
Sample SPFx React web part which allows sending emails using Microsoft Graph.
|
||||
|
||||
![Sending emails with SPFx web part](./assets/preview.gif)
|
||||
|
||||
## Used SharePoint Framework Version
|
||||
|
||||
![drop](https://img.shields.io/badge/version-GA-green.svg)
|
||||
|
||||
## Applies to
|
||||
|
||||
* [SharePoint Framework](https:/dev.office.com/sharepoint)
|
||||
* [Office 365 tenant](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment)
|
||||
|
||||
## Solution
|
||||
|
||||
Solution|Author(s)
|
||||
--------|---------
|
||||
react-graph-feedback-form|Sergei Zheleznov (CollabStack)
|
||||
|
||||
## Version history
|
||||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.0|August 12, 2019|Initial release
|
||||
|
||||
|
||||
## Disclaimer
|
||||
|
||||
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||
|
||||
---
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
* clone this repo
|
||||
* in the command line run:
|
||||
* `npm i`
|
||||
* `gulp bundle --ship`
|
||||
* `gulp package-solution --ship`
|
||||
* deploy the package to your app catalog
|
||||
* approve the API permission request to access e-mails using Microsoft Graph
|
||||
* add the web part to a page
|
||||
|
||||
## Features
|
||||
|
||||
This sample illustrates the following concepts:
|
||||
|
||||
* using MSGraphClient to communicate with the Microsoft Graph in a SharePoint Framework solution
|
||||
* requesting API permissions in a SharePoint Framework package
|
||||
* sending e-mails using Microsoft Graph
|
||||
* using MSGraphClient in a SharePoint Framework web part
|
||||
* using @microsoft/microsoft-graph-types
|
||||
|
||||
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-graph-feedback-form" />
|
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"feedback-form-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/feedbackForm/FeedbackFormWebPart.js",
|
||||
"manifest": "./src/webparts/feedbackForm/FeedbackFormWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"FeedbackFormWebPartStrings": "lib/webparts/feedbackForm/loc/{locale}.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||
"deployCdnPath": "temp/deploy"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||
"workingDir": "./temp/deploy/",
|
||||
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||
"container": "spfx-feedback-form",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "spfx-feedback-form-client-side-solution",
|
||||
"id": "8cf91ad7-be8e-4f6c-a1eb-a790f3ef5a32",
|
||||
"version": "1.0.0.4",
|
||||
"includeClientSideAssets": true,
|
||||
"isDomainIsolated": false,
|
||||
"webApiPermissionRequests": [
|
||||
{
|
||||
"resource": "Microsoft Graph",
|
||||
"scope": "Mail.Send.Shared"
|
||||
}
|
||||
]
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/spfx-feedback-form.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://localhost:5432/workbench",
|
||||
"api": {
|
||||
"port": 5432,
|
||||
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const gulp = require('gulp');
|
||||
const build = require('@microsoft/sp-build-web');
|
||||
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||
|
||||
build.initialize(gulp);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "react-graph-feedback-form",
|
||||
"version": "1.0.0",
|
||||
"author": {
|
||||
"name": "Sergei Zheleznov",
|
||||
"url": "https://collabstack.de"
|
||||
},
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "16.7.0",
|
||||
"react-dom": "16.7.0",
|
||||
"@types/react": "16.7.22",
|
||||
"@types/react-dom": "16.8.0",
|
||||
"office-ui-fabric-react": "6.143.0",
|
||||
"@microsoft/sp-core-library": "1.8.2",
|
||||
"@microsoft/sp-property-pane": "1.8.2",
|
||||
"@microsoft/sp-webpart-base": "1.8.2",
|
||||
"@microsoft/sp-lodash-subset": "1.8.2",
|
||||
"@microsoft/sp-office-ui-fabric-core": "1.8.2",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"@types/es6-promise": "0.0.33"
|
||||
},
|
||||
"resolutions": {
|
||||
"@types/react": "16.7.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/microsoft-graph-types": "^1.10.0",
|
||||
"@microsoft/rush-stack-compiler-2.9": "0.7.7",
|
||||
"@microsoft/sp-build-web": "1.8.2",
|
||||
"@microsoft/sp-module-interfaces": "1.8.2",
|
||||
"@microsoft/sp-tslint-rules": "1.8.2",
|
||||
"@microsoft/sp-webpart-workbench": "1.8.2",
|
||||
"@types/chai": "3.4.34",
|
||||
"@types/mocha": "2.2.38",
|
||||
"ajv": "~5.2.2",
|
||||
"gulp": "~3.9.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "b51cbb3f-5a87-4003-b6e8-b1f88b4cf60c",
|
||||
"alias": "FeedbackFormWebPart",
|
||||
"componentType": "WebPart",
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
"requiresCustomScript": false,
|
||||
"supportedHosts": ["SharePointWebPart"],
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70",
|
||||
"group": { "default": "Other" },
|
||||
"title": { "default": "Feedback Form" },
|
||||
"description": { "default": "FeedbackForm description" },
|
||||
"officeFabricIconFontName": "Page",
|
||||
"properties": {
|
||||
"description": "FeedbackForm"
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||
import {
|
||||
IPropertyPaneConfiguration,
|
||||
PropertyPaneTextField
|
||||
} from '@microsoft/sp-property-pane';
|
||||
|
||||
import * as strings from 'FeedbackFormWebPartStrings';
|
||||
import FeedbackForm from './components/FeedbackForm';
|
||||
import { IFeedbackFormProps } from './components/IFeedbackFormProps';
|
||||
import { MSGraphClient } from '@microsoft/sp-http';
|
||||
|
||||
export interface IFeedbackFormWebPartProps {
|
||||
targetEmail: string;
|
||||
subject: string;
|
||||
}
|
||||
|
||||
export default class FeedbackFormWebPart extends BaseClientSideWebPart<IFeedbackFormWebPartProps> {
|
||||
|
||||
private _graphClient: MSGraphClient;
|
||||
|
||||
public onInit(): Promise<void> {
|
||||
return new Promise<void>((resolve: () => void, reject: (error: any) => void ): void => {
|
||||
this.context.msGraphClientFactory
|
||||
.getClient()
|
||||
.then((cli: MSGraphClient): void => {
|
||||
this._graphClient = cli;
|
||||
resolve();
|
||||
}, err => reject(err));
|
||||
});
|
||||
}
|
||||
|
||||
public render(): void {
|
||||
const element: React.ReactElement<IFeedbackFormProps> = React.createElement(
|
||||
FeedbackForm,
|
||||
{
|
||||
graphClient: this._graphClient,
|
||||
targetEmail: this.properties.targetEmail,
|
||||
subject: this.properties.subject
|
||||
}
|
||||
);
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected onDispose(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
|
||||
protected get dataVersion(): Version {
|
||||
return Version.parse('1.0');
|
||||
}
|
||||
|
||||
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||
return {
|
||||
pages: [
|
||||
{
|
||||
header: {
|
||||
description: strings.PropertyPaneDescription
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
groupName: strings.BasicGroupName,
|
||||
groupFields: [
|
||||
PropertyPaneTextField('targetEmail', {
|
||||
label: strings.TargetEmailFieldLabel
|
||||
}),
|
||||
PropertyPaneTextField('subject', {
|
||||
label: strings.SubjectFieldLabel
|
||||
})
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
||||
|
||||
.feedbackForm {
|
||||
max-width: 700px;
|
||||
margin: 0px auto;
|
||||
.formActions {
|
||||
margin: 10px 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
import * as React from 'react';
|
||||
import styles from './FeedbackForm.module.scss';
|
||||
import { IFeedbackFormProps } from './IFeedbackFormProps';
|
||||
import { escape } from '@microsoft/sp-lodash-subset';
|
||||
import {
|
||||
TextField,
|
||||
DefaultButton,
|
||||
MessageBar,
|
||||
MessageBarType,
|
||||
MessageBarButton
|
||||
} from 'office-ui-fabric-react';
|
||||
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
|
||||
|
||||
export interface IFeedbackFormState {
|
||||
isBusy: boolean;
|
||||
message: string;
|
||||
messageSended: boolean;
|
||||
}
|
||||
|
||||
export default class FeedbackForm extends React.Component<IFeedbackFormProps, IFeedbackFormState> {
|
||||
|
||||
constructor(props){
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
isBusy: false,
|
||||
message: '',
|
||||
messageSended: false
|
||||
};
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<IFeedbackFormProps> {
|
||||
return (
|
||||
<div className={ styles.feedbackForm }>
|
||||
{this.props.targetEmail ? '' : (
|
||||
<MessageBar messageBarType={MessageBarType.warning}>Target email is empty! Please configure this web part first.</MessageBar>
|
||||
)}
|
||||
{this.state.messageSended ? (
|
||||
<MessageBar
|
||||
actions={
|
||||
<div>
|
||||
<MessageBarButton onClick={()=>{
|
||||
this.setState({
|
||||
messageSended:false
|
||||
});
|
||||
}}>I want to send more!</MessageBarButton>
|
||||
</div>
|
||||
}
|
||||
messageBarType={MessageBarType.success}
|
||||
isMultiline={false}
|
||||
>
|
||||
Message was sent!
|
||||
</MessageBar>
|
||||
) :
|
||||
(
|
||||
<>
|
||||
<TextField disabled={this.state.isBusy} label="Feedback" multiline rows={3} name="text" value={this.state.message} onChange={this._onChange} />
|
||||
<div className={ styles.formActions }>
|
||||
<DefaultButton disabled={this.state.isBusy || !this.props.targetEmail} onClick={this._sendMessage}>Send</DefaultButton>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private _onChange = (event: React.ChangeEvent<HTMLInputElement>) : void => {
|
||||
this.setState({message:event.target.value});
|
||||
}
|
||||
|
||||
private _sendMessage = async (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) : Promise<void> => {
|
||||
this.setState({isBusy:true});
|
||||
|
||||
const msg = {
|
||||
subject: escape(this.props.subject),
|
||||
importance:"low",
|
||||
body:{
|
||||
contentType:"html",
|
||||
content: escape(this.state.message)
|
||||
},
|
||||
toRecipients:[
|
||||
{
|
||||
emailAddress:{
|
||||
address: this.props.targetEmail
|
||||
}
|
||||
}
|
||||
]
|
||||
} as MicrosoftGraph.Message;
|
||||
|
||||
await this.props.graphClient.api('/me/sendMail')
|
||||
.post({
|
||||
message : msg
|
||||
}).then(() => {
|
||||
this.setState({
|
||||
isBusy:false,
|
||||
message: '',
|
||||
messageSended: true
|
||||
});
|
||||
},(error: any) => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import { MSGraphClient } from '@microsoft/sp-http';
|
||||
|
||||
export interface IFeedbackFormProps {
|
||||
graphClient: MSGraphClient;
|
||||
targetEmail: string;
|
||||
subject: string;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Description",
|
||||
"BasicGroupName": "Group Name",
|
||||
"DescriptionFieldLabel": "Description Field",
|
||||
"TargetEmailFieldLabel": "Target Email",
|
||||
"SubjectFieldLabel": "Subject"
|
||||
}
|
||||
});
|
11
samples/react-graph-feedback-form/src/webparts/feedbackForm/loc/mystrings.d.ts
vendored
Normal file
11
samples/react-graph-feedback-form/src/webparts/feedbackForm/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
declare interface IFeedbackFormWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
TargetEmailFieldLabel: string;
|
||||
SubjectFieldLabel: string;
|
||||
}
|
||||
|
||||
declare module 'FeedbackFormWebPartStrings' {
|
||||
const strings: IFeedbackFormWebPartStrings;
|
||||
export = strings;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"extends": "./node_modules/@microsoft/rush-stack-compiler-2.9/includes/tsconfig-web.json",
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib",
|
||||
"inlineSources": false,
|
||||
"strictNullChecks": false,
|
||||
"noUnusedLocals": false,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@microsoft"
|
||||
],
|
||||
"types": [
|
||||
"es6-promise",
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"lib"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
|
||||
"rules": {
|
||||
"class-name": false,
|
||||
"export-name": false,
|
||||
"forin": false,
|
||||
"label-position": false,
|
||||
"member-access": true,
|
||||
"no-arg": false,
|
||||
"no-console": false,
|
||||
"no-construct": false,
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": false,
|
||||
"no-function-expression": true,
|
||||
"no-internal-module": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-unnecessary-semicolons": true,
|
||||
"no-unused-expression": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-with-statement": true,
|
||||
"semicolon": true,
|
||||
"trailing-comma": false,
|
||||
"typedef": false,
|
||||
"typedef-whitespace": false,
|
||||
"use-named-parameter": true,
|
||||
"variable-name": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue