From 102fa0a24b019f5c32625ed4727ae521f525523d Mon Sep 17 00:00:00 2001 From: Pedro Bonamin <46196328+pedrobonamin@users.noreply.github.com> Date: Mon, 1 Jul 2024 12:44:59 +0200 Subject: [PATCH] feat(corel): integrate bundles store (#7040) * feat(corel): add bundles store --- .../__workshop__/BundlesStoreStory.tsx | 110 +++++++++++++ .../bundles/__workshop__/ReleaseForm.tsx | 133 ++++++++++++++++ .../core/store/bundles/__workshop__/index.ts | 14 ++ .../sanity/src/core/store/bundles/index.ts | 1 + .../sanity/src/core/store/bundles/reducer.ts | 109 +++++++++++++ .../sanity/src/core/store/bundles/types.ts | 12 ++ .../core/store/bundles/useBundleOperations.ts | 50 ++++++ .../src/core/store/bundles/useBundlesStore.ts | 149 ++++++++++++++++++ 8 files changed, 578 insertions(+) create mode 100644 packages/sanity/src/core/store/bundles/__workshop__/BundlesStoreStory.tsx create mode 100644 packages/sanity/src/core/store/bundles/__workshop__/ReleaseForm.tsx create mode 100644 packages/sanity/src/core/store/bundles/__workshop__/index.ts create mode 100644 packages/sanity/src/core/store/bundles/index.ts create mode 100644 packages/sanity/src/core/store/bundles/reducer.ts create mode 100644 packages/sanity/src/core/store/bundles/types.ts create mode 100644 packages/sanity/src/core/store/bundles/useBundleOperations.ts create mode 100644 packages/sanity/src/core/store/bundles/useBundlesStore.ts diff --git a/packages/sanity/src/core/store/bundles/__workshop__/BundlesStoreStory.tsx b/packages/sanity/src/core/store/bundles/__workshop__/BundlesStoreStory.tsx new file mode 100644 index 00000000000..cd554fe5b86 --- /dev/null +++ b/packages/sanity/src/core/store/bundles/__workshop__/BundlesStoreStory.tsx @@ -0,0 +1,110 @@ +import {Card, Flex, Stack, Text} from '@sanity/ui' +import {type ComponentType, type FormEvent, useCallback, useState} from 'react' + +import {Button} from '../../../../ui-components' +import {LoadingBlock} from '../../../components/loadingBlock/LoadingBlock' +import {AddonDatasetProvider} from '../../../studio/addonDataset/AddonDatasetProvider' +import {type BundleDocument} from '../types' +import {useBundleOperations} from '../useBundleOperations' +import {useBundlesStore} from '../useBundlesStore' +import {ReleaseForm} from './ReleaseForm' + +const WithAddonDatasetProvider =

(Component: ComponentType

): React.FC

=> { + const WrappedComponent: React.FC

= (props) => ( + + + + ) + WrappedComponent.displayName = `WithAddonDatasetProvider(${Component.displayName || Component.name || 'Component'})` + + return WrappedComponent +} + +const initialValue = {name: '', title: '', tone: undefined, publishAt: undefined} +const BundlesStoreStory = () => { + const {data, loading} = useBundlesStore() + const {createBundle, deleteBundle} = useBundleOperations() + const [creating, setCreating] = useState(false) + const [deleting, setDeleting] = useState(null) + const [value, setValue] = useState>(initialValue) + const handleCreateBundle = useCallback( + async (event: FormEvent) => { + try { + event.preventDefault() + setCreating(true) + await createBundle(value) + setValue(initialValue) + } catch (err) { + console.error(err) + } finally { + setCreating(false) + } + }, + [createBundle, value], + ) + + const handleDeleteBundle = useCallback( + async (id: string) => { + try { + setDeleting(id) + await deleteBundle(id) + } catch (err) { + console.error(err) + } finally { + setDeleting(null) + } + }, + [deleteBundle], + ) + + return ( + + + +

+ + Create a new release + + +