-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(website): update code snippets for development_notifications
- Loading branch information
Showing
48 changed files
with
1,714 additions
and
796 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
website/src/code-examples/development/forms/channels-create-with-modal.jsx
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,46 @@ | ||
|
||
import { useCallback } from 'react'; | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
import { FormModalPage } from '@commercetools-frontend/application-components'; | ||
import { docToFormValues, formValuesToDoc } from './conversions'; | ||
import ChannelsForm from './channels-form'; | ||
|
||
const ChannelsCreate = (props) => { | ||
const languages = useApplicationContext((context) => context.project.languages); | ||
const handleSubmit = useCallback( | ||
async (formValues) => { | ||
const data = formValuesToDoc(formValues); | ||
// This would trigger the request, for example a mutation. | ||
const result = await createChannel(data); | ||
// If successful, show a notification and redirect | ||
// to the Channels details page. | ||
// If errored, show an error notification. | ||
}, | ||
[createChannel] | ||
); | ||
|
||
return ( | ||
<ChannelsForm | ||
initialValues={docToFormValues(null, languages)} | ||
onSubmit={handleSubmit} | ||
> | ||
{(formProps) => { | ||
return ( | ||
<FormModalPage | ||
title="Create a channel" | ||
isOpen | ||
onClose={props.onClose} | ||
isPrimaryButtonDisabled={formProps.isSubmitting} | ||
onSecondaryButtonClick={() => { | ||
formProps.handleCancel(); | ||
props.onClose() | ||
}} | ||
onPrimaryButtonClick={formProps.submitForm} | ||
> | ||
{formProps.formElements} | ||
</FormModalPage> | ||
) | ||
}} | ||
</ChannelsForm> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
website/src/code-examples/development/forms/channels-create-with-modal.tsx
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,46 @@ | ||
|
||
import { useCallback } from 'react'; | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
import { FormModalPage } from '@commercetools-frontend/application-components'; | ||
import { docToFormValues, formValuesToDoc } from './conversions'; | ||
import ChannelsForm from './channels-form'; | ||
|
||
const ChannelsCreate = (props) => { | ||
const languages = useApplicationContext((context) => context.project.languages); | ||
const handleSubmit = useCallback( | ||
async (formValues) => { | ||
const data = formValuesToDoc(formValues); | ||
// This would trigger the request, for example a mutation. | ||
const result = await createChannel(data); | ||
// If successful, show a notification and redirect | ||
// to the Channels details page. | ||
// If errored, show an error notification. | ||
}, | ||
[createChannel] | ||
); | ||
|
||
return ( | ||
<ChannelsForm | ||
initialValues={docToFormValues(null, languages)} | ||
onSubmit={handleSubmit} | ||
> | ||
{(formProps) => { | ||
return ( | ||
<FormModalPage | ||
title="Create a channel" | ||
isOpen | ||
onClose={props.onClose} | ||
isPrimaryButtonDisabled={formProps.isSubmitting} | ||
onSecondaryButtonClick={() => { | ||
formProps.handleCancel(); | ||
props.onClose() | ||
}} | ||
onPrimaryButtonClick={formProps.submitForm} | ||
> | ||
{formProps.formElements} | ||
</FormModalPage> | ||
) | ||
}} | ||
</ChannelsForm> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
website/src/code-examples/development/forms/channels-create.jsx
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,33 @@ | ||
import { useCallback } from 'react'; | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
import Text from '@commercetools-uikit/text'; | ||
import Spacings from '@commercetools-uikit/spacings'; | ||
import { docToFormValues, formValuesToDoc } from './conversions'; | ||
import ChannelsForm from './channels-form'; | ||
|
||
const ChannelsCreate = () => { | ||
const languages = useApplicationContext((context) => context.project.languages); | ||
const handleSubmit = useCallback( | ||
async (formValues) => { | ||
const data = formValuesToDoc(formValues); | ||
// This would trigger the request, for example a mutation. | ||
const result = await createChannel(data); | ||
// If successful, show a notification and redirect | ||
// to the Channels details page. | ||
// If errored, show an error notification. | ||
}, | ||
[createChannel] | ||
); | ||
|
||
return ( | ||
<Spacings.Stack scale="xl"> | ||
<Text.Headline as="h1"> | ||
Create a channel | ||
</Text.Headline> | ||
<ChannelsForm | ||
initialValues={docToFormValues(null, languages)} | ||
onSubmit={handleSubmit} | ||
/> | ||
</Spacings.Stack> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
website/src/code-examples/development/forms/channels-create.tsx
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,33 @@ | ||
import { useCallback } from 'react'; | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
import Text from '@commercetools-uikit/text'; | ||
import Spacings from '@commercetools-uikit/spacings'; | ||
import { docToFormValues, formValuesToDoc } from './conversions'; | ||
import ChannelsForm from './channels-form'; | ||
|
||
const ChannelsCreate = () => { | ||
const languages = useApplicationContext((context) => context.project.languages); | ||
const handleSubmit = useCallback( | ||
async (formValues) => { | ||
const data = formValuesToDoc(formValues); | ||
// This would trigger the request, for example a mutation. | ||
const result = await createChannel(data); | ||
// If successful, show a notification and redirect | ||
// to the Channels details page. | ||
// If errored, show an error notification. | ||
}, | ||
[createChannel] | ||
); | ||
|
||
return ( | ||
<Spacings.Stack scale="xl"> | ||
<Text.Headline as="h1"> | ||
Create a channel | ||
</Text.Headline> | ||
<ChannelsForm | ||
initialValues={docToFormValues(null, languages)} | ||
onSubmit={handleSubmit} | ||
/> | ||
</Spacings.Stack> | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
website/src/code-examples/development/forms/channels-details-with-modal.jsx
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,52 @@ | ||
import { useCallback } from 'react'; | ||
import { useRouteMatch } from "react-router-dom"; | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
import { FormModalPage } from '@commercetools-frontend/application-components'; | ||
import LoadingSpinner from '@commercetools-uikit/loading-spinner'; | ||
import useChannelsFetcher from './use-channels-fetcher'; | ||
import useChannelsUpdater from './use-channels-updater'; | ||
import { docToFormValues, formValuesToDoc } from './conversions'; | ||
import ChannelsForm from './channels-form'; | ||
|
||
const ChannelsDetails = (props) => { | ||
const match = useRouteMatch(); | ||
const languages = useApplicationContext((context) => context.project.languages); | ||
const { data: channel } = useChannelsFetcher(match.params.id) | ||
const { updateChannel } = useChannelsUpdater(match.params.id) | ||
const handleSubmit = useCallback( | ||
async (formValues) => { | ||
const data = formValuesToDoc(formValues); | ||
// This would trigger the request, for example a mutation. | ||
const result = await updateChannel(data); | ||
// If successful, show a notification. | ||
// If errored, show an error notification. | ||
}, | ||
[updateChannel] | ||
); | ||
|
||
if (!channel) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
return ( | ||
<ChannelsForm | ||
initialValues={docToFormValues(channel, languages)} | ||
onSubmit={handleSubmit} | ||
> | ||
{(formProps) => { | ||
return ( | ||
<FormModalPage | ||
title="Manage Channel" | ||
isOpen | ||
onClose={props.onClose} | ||
isPrimaryButtonDisabled={formProps.isSubmitting} | ||
onSecondaryButtonClick={formProps.handleCancel} | ||
onPrimaryButtonClick={formProps.submitForm} | ||
> | ||
{formProps.formElements} | ||
</FormModalPage> | ||
) | ||
}} | ||
</ChannelsForm> | ||
); | ||
} |
65 changes: 65 additions & 0 deletions
65
website/src/code-examples/development/forms/channels-details-with-modal.tsx
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,65 @@ | ||
import { ReactNode, useCallback } from 'react'; | ||
import { useRouteMatch } from "react-router-dom"; | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
import { FormModalPage } from '@commercetools-frontend/application-components'; | ||
import LoadingSpinner from '@commercetools-uikit/loading-spinner'; | ||
import useChannelsFetcher from './use-channels-fetcher'; | ||
import useChannelsUpdater from './use-channels-updater'; | ||
import { docToFormValues, formValuesToDoc } from './conversions'; | ||
import ChannelsForm from './channels-form'; | ||
|
||
type ChannelsDetailsProps = { | ||
onClose: () => void; | ||
// ... | ||
} | ||
|
||
type FormProps = { | ||
isSubmitting: boolean; | ||
handleCancel: () => void; | ||
submitForm: () => void; | ||
formElements: ReactNode | ||
// ... | ||
} | ||
|
||
const ChannelsDetails = (props: ChannelsDetailsProps) => { | ||
const match = useRouteMatch(); | ||
const languages = useApplicationContext((context) => context.project.languages); | ||
const { data: channel } = useChannelsFetcher(match.params.id) | ||
const { updateChannel } = useChannelsUpdater(match.params.id) | ||
const handleSubmit = useCallback( | ||
async (formValues) => { | ||
const data = formValuesToDoc(formValues); | ||
// This would trigger the request, for example a mutation. | ||
const result = await updateChannel(data); | ||
// If successful, show a notification. | ||
// If errored, show an error notification. | ||
}, | ||
[updateChannel] | ||
); | ||
|
||
if (!channel) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
return ( | ||
<ChannelsForm | ||
initialValues={docToFormValues(channel, languages)} | ||
onSubmit={handleSubmit} | ||
> | ||
{(formProps: FormProps) => { | ||
return ( | ||
<FormModalPage | ||
title="Manage Channel" | ||
isOpen | ||
onClose={props.onClose} | ||
isPrimaryButtonDisabled={formProps.isSubmitting} | ||
onSecondaryButtonClick={formProps.handleCancel} | ||
onPrimaryButtonClick={formProps.submitForm} | ||
> | ||
{formProps.formElements} | ||
</FormModalPage> | ||
) | ||
}} | ||
</ChannelsForm> | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
website/src/code-examples/development/forms/channels-details.jsx
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,43 @@ | ||
import { useCallback } from 'react'; | ||
import { useRouteMatch } from "react-router-dom"; | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
import Text from '@commercetools-uikit/text'; | ||
import Spacings from '@commercetools-uikit/spacings'; | ||
import LoadingSpinner from '@commercetools-uikit/loading-spinner'; | ||
import useChannelsFetcher from './use-channels-fetcher'; | ||
import useChannelsUpdater from './use-channels-updater'; | ||
import { docToFormValues, formValuesToDoc } from './conversions'; | ||
import ChannelsForm from './channels-form'; | ||
|
||
const ChannelsDetails = (props) => { | ||
const match = useRouteMatch(); | ||
const languages = useApplicationContext((context) => context.project.languages); | ||
const { data: channel } = useChannelsFetcher(match.params.id) | ||
const { updateChannel } = useChannelsUpdater(match.params.id) | ||
const handleSubmit = useCallback( | ||
async (formValues) => { | ||
const data = formValuesToDoc(formValues); | ||
// This would trigger the request, for example a mutation. | ||
const result = await updateChannel(data); | ||
// If successful, show a notification. | ||
// If errored, show an error notification. | ||
}, | ||
[updateChannel] | ||
); | ||
|
||
if (!channel) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
return ( | ||
<Spacings.Stack scale="xl"> | ||
<Text.Headline as="h1"> | ||
Manage Channel | ||
</Text.Headline> | ||
<ChannelsForm | ||
initialValues={docToFormValues(channel, languages)} | ||
onSubmit={handleSubmit} | ||
/> | ||
</Spacings.Stack> | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
website/src/code-examples/development/forms/channels-details.tsx
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,43 @@ | ||
import { useCallback } from 'react'; | ||
import { useRouteMatch } from "react-router-dom"; | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
import Text from '@commercetools-uikit/text'; | ||
import Spacings from '@commercetools-uikit/spacings'; | ||
import LoadingSpinner from '@commercetools-uikit/loading-spinner'; | ||
import useChannelsFetcher from './use-channels-fetcher'; | ||
import useChannelsUpdater from './use-channels-updater'; | ||
import { docToFormValues, formValuesToDoc } from './conversions'; | ||
import ChannelsForm from './channels-form'; | ||
|
||
const ChannelsDetails = (props) => { | ||
const match = useRouteMatch(); | ||
const languages = useApplicationContext((context) => context.project.languages); | ||
const { data: channel } = useChannelsFetcher(match.params.id) | ||
const { updateChannel } = useChannelsUpdater(match.params.id) | ||
const handleSubmit = useCallback( | ||
async (formValues) => { | ||
const data = formValuesToDoc(formValues); | ||
// This would trigger the request, for example a mutation. | ||
const result = await updateChannel(data); | ||
// If successful, show a notification. | ||
// If errored, show an error notification. | ||
}, | ||
[updateChannel] | ||
); | ||
|
||
if (!channel) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
return ( | ||
<Spacings.Stack scale="xl"> | ||
<Text.Headline as="h1"> | ||
Manage Channel | ||
</Text.Headline> | ||
<ChannelsForm | ||
initialValues={docToFormValues(channel, languages)} | ||
onSubmit={handleSubmit} | ||
/> | ||
</Spacings.Stack> | ||
); | ||
} |
Oops, something went wrong.