-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #601 from TheNileDev/jrea/org-form
feat(react): add org form
- Loading branch information
Showing
5 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Organization creation form | ||
|
||
A form for a name of an organization. | ||
|
||
## Usage | ||
|
||
```typescript | ||
import { OrganizationForm, NileProvider } from '@theniledev/react'; | ||
|
||
const API_URL = 'http://localhost:8080'; // location of the Nile endpoint | ||
|
||
function App() { | ||
return ( | ||
<NileProvider basePath={API_URL}> | ||
<h1>🤩 My Great App🤩</h1> | ||
<h2>Create an organization</h2> | ||
<OrganizationForm | ||
onSuccess={(data) => { | ||
console.log('the created org:', data); | ||
}} | ||
/> | ||
</NileProvider> | ||
); | ||
} | ||
``` | ||
|
||
## Theming | ||
|
||
[theming](../../../README.md#UI%20customization) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { CreateOrganizationRequest, Organization } from '@theniledev/js'; | ||
|
||
import { useNile } from '../../context'; | ||
import { useMutation } from '../../lib/queries'; | ||
import SimpleForm, { AttributeType } from '../../lib/SimpleForm'; | ||
|
||
import { Props } from './types'; | ||
|
||
const attributes = [ | ||
{ | ||
name: 'name', | ||
label: 'Organization name', | ||
type: AttributeType.Text, | ||
defaultValue: '', | ||
required: true, | ||
}, | ||
]; | ||
|
||
export default function AddOrgForm(props: Props) { | ||
const { onSuccess, onError, cancelLink } = props; | ||
const nile = useNile(); | ||
|
||
const mutation = useMutation( | ||
(data: CreateOrganizationRequest) => | ||
nile.organizations.createOrganization({ | ||
createOrganizationRequest: data, | ||
}), | ||
{ | ||
onSuccess: (data: Organization) => { | ||
onSuccess(data); | ||
}, | ||
onError: (e: Error) => { | ||
onError && onError(e as Error); | ||
}, | ||
} | ||
); | ||
|
||
return ( | ||
<SimpleForm | ||
mutation={mutation} | ||
buttonText="Create organization" | ||
attributes={attributes} | ||
cancelLink={cancelLink} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Organization } from '@theniledev/js'; | ||
|
||
type OrgCreateSuccess = (org: Organization) => void; | ||
|
||
export interface Props { | ||
onSuccess: OrgCreateSuccess; | ||
onError?: (error: Error) => void; | ||
cancelLink?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { Story } from '@storybook/react'; | ||
|
||
import OrganizationForm from '../src/components/OrganizationForm'; | ||
import { NileProvider } from '../src/context'; | ||
|
||
const meta = { | ||
component: OrganizationForm, | ||
args: { | ||
org: 'myOrg', | ||
}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: Story = () => ( | ||
<NileProvider basePath="http://localhost:8080"> | ||
<div style={{ maxWidth: '20rem', margin: '0 auto' }}> | ||
<OrganizationForm | ||
onSuccess={() => alert('success!')} | ||
cancelLink="#linkToSomewhere" | ||
/> | ||
</div> | ||
</NileProvider> | ||
); | ||
|
||
export const Default = Template.bind({}); |
007bda5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nile-js – ./
nile-js-theniledev.vercel.app
nile-js.vercel.app
nile-js-git-master-theniledev.vercel.app
007bda5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-storybook – ./packages/react
react-storybook-ten.vercel.app
react-storybook-git-master-theniledev.vercel.app
react-storybook-theniledev.vercel.app