How to use the @webiny/app/hooks/useHandlers.useHandlers function in @webiny/app

To help you get started, we’ve selected a few @webiny/app examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages / app-page-builder / src / admin / utils / components / Title.js View on Github external
const Title = (props: Object) => {
    const { plugin: pluginName, title } = props;

    const client = useApolloClient();
    const [editDialogOpened, setEditDialog] = useState(false);
    const { showSnackbar } = useSnackbar();

    const openEditDialog = useCallback(() => setEditDialog(true), []);
    const closeEditDialog = useCallback(() => setEditDialog(false), []);

    const { onSubmit } = useHandlers(props, {
        onSubmit: ({ id, refresh }) => async plugin => {
            const { title: name } = plugin;
            const response = await client.mutate({
                mutation: updateElement,
                variables: {
                    id,
                    data: { name }
                }
            });

            const { error, data } = response.data.pageBuilder.updateElement;
            if (error) {
                closeEditDialog();
                setTimeout(() => {
                    // For better UX, success message is shown after 300ms has passed.
                    showSnackbar(error.message);
github webiny / webiny-js / packages / app-page-builder / src / admin / views / Menus / MenusForm / MenuItems / MenuItemForm.js View on Github external
const MenuItemForm = (props: Object) => {
    const { onCancel, onSubmit } = useHandlers(props, {
        onCancel: ({ editItem, currentMenuItem, deleteItem }) => () => {
            if (currentMenuItem.__new) {
                deleteItem(currentMenuItem);
            } else {
                editItem(null);
            }
        },
        onSubmit: ({ items, onChange, editItem }) => data => {
            const item = omit(omitBy(data, isNull), ["__new"]);
            if (item.id) {
                const target = findObject(items, item.id);
                if (target) {
                    target.source[target.index] = item;
                    onChange([...items]);
                }
            } else {
github webiny / webiny-js / packages / app-forms / src / admin / plugins / formDetails / formRevisions / useRevision.js View on Github external
export const useRevision = ({ revision, form }) => {
    const { history } = useReactRouter();
    const { showSnackbar } = useSnackbar();
    const client = useApolloClient();

    const {
        createRevision,
        editRevision,
        deleteRevision,
        publishRevision,
        unpublishRevision
    } = useHandlers(null, {
        createRevision: () => async () => {
            const { data: res } = await client.mutate({
                mutation: CREATE_REVISION_FROM,
                variables: { revision: revision.id },
                refetchQueries: ["FormsListForms"]
            });
            const { data, error } = res.forms.revision;

            if (error) {
                return showSnackbar(error.message);
            }

            history.push(`/forms/${data.id}`);
        },
        editRevision: () => () => {
            history.push(`/forms/${revision.id}`);