Skip to content

Commit

Permalink
feat(#27): notification on collection create
Browse files Browse the repository at this point in the history
  • Loading branch information
notmedia committed Dec 3, 2022
1 parent 4690bc6 commit 0cfa7a5
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/app/components/notification/notification-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const NotificationContainer: React.FC = () => {
<StyledToastContainer
position="bottom-right"
autoClose={3000}
newestOnTop
pauseOnFocusLoss
pauseOnHover
closeButton={false}
Expand Down
12 changes: 11 additions & 1 deletion src/app/pages/collections/forms/collection.form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,17 @@ export const CollectionForm: React.FC<CollectionFormProps> = ({

return (
<form id={id} onSubmit={handleSubmit(onSubmit)}>
<Container gap={0} css={{ display: 'flex', flexDirection: 'column' }}>
<Container
gap={0}
display="flex"
direction="column"
wrap="nowrap"
css={{
overflow: 'hidden',
paddingLeft: 1,
paddingRight: 1,
}}
>
<Input
autoFocus
bordered
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/collections/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './use-create-collection';
33 changes: 33 additions & 0 deletions src/app/pages/collections/hooks/use-create-collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { notification } from '@components';
import { Collection, CollectionType, useCollectionsStore } from '@storage';

export function useCreateCollection() {
const createCollection = useCollectionsStore((store) => store.createCollection);

const create = async (payload: Collection<CollectionType>) => {
try {
await createCollection({
...payload,
type: CollectionType.GRPC,
});

notification(
{
title: `${payload.name}`,
description: 'Collection successfully created',
},
{ type: 'success' }
);
} catch (error: any) {
notification(
{
title: `Create collection error`,
description: error?.message,
},
{ type: 'error' }
);
}
};

return { create };
}
10 changes: 6 additions & 4 deletions src/app/pages/collections/modals/create-collection.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { Button, Modal, ModalProps, Spacer, Switch, Text } from '@nextui-org/rea
import React from 'react';

import { Badge } from '@components';
import { Collection, CollectionType, useCollectionsStore } from '@storage';
import { Collection, CollectionType } from '@storage';

import { CollectionForm } from '../forms';
import { useCreateCollection } from '../hooks';

export const CreateCollectionModal: React.FC<ModalProps> = ({ onClose = () => {}, ...props }) => {
const createCollection = useCollectionsStore((store) => store.createCollection);
const { create } = useCreateCollection();
const [isCreateMore, setIsCreateMore] = React.useState(false);
const [defaultValues, setDefaultValues] = React.useState({});

const handleSubmit = async (payload: Collection<CollectionType>) => {
await createCollection({
await create({
...payload,
type: CollectionType.GRPC,
});
Expand All @@ -32,7 +33,8 @@ export const CreateCollectionModal: React.FC<ModalProps> = ({ onClose = () => {}
return (
<Modal
aria-labelledby="create-collection-modal"
css={{ background: '$background' }}
css={{ background: '$background', zIndex: '1 important!' }}
width="70%"
onClose={onClose}
{...props}
>
Expand Down
1 change: 0 additions & 1 deletion src/app/pages/side-bar/side-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const SideBar: React.FC = () => {
/>
</Tooltip>
<CreateCollectionModal
fullScreen
closeButton
open={context?.modal.createCollectionModalVisible}
onClose={() => context?.modal.setCreateCollectionModalVisible(false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export const SendHeader: React.FC<PropsWithChildren<SendHeaderProps<GrpcMethodTy
</Container>
<CreateEnvironmentModal
closeButton
blur
open={createEnvironmentModalVisible}
defaultValues={{
url: tab.data.url || '',
Expand Down
38 changes: 13 additions & 25 deletions src/app/storage/collections.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
GrpcMethod,
GrpcService,
} from './interfaces';
// import { useLogsStore } from './logs.storage';
import { useTabsStore } from './tabs.storage';

export const useCollectionsStore = create(
Expand All @@ -24,32 +23,21 @@ export const useCollectionsStore = create(
collections: [],
createCollection: async (collection) => {
if (collection.type === CollectionType.GRPC) {
try {
const proto = await window.protobuf.loadFromFile(collection.options);
const proto = await window.protobuf.loadFromFile(collection.options);

set(
produce<CollectionsStorage>((state) => {
state.collections.push({
...collection,
set(
produce<CollectionsStorage>((state) => {
state.collections.push({
...collection,
id: nanoid(),
children: proto.map((service) => ({
...service,
id: nanoid(),
children: proto.map((service) => ({
...service,
id: nanoid(),
methods: (service.methods || []).map((method) => ({ ...method, id: nanoid() })),
})),
});
})
);
} catch (error: any) {
notification(
{
title: `Create collection error`,
description: error?.message,
},
{ type: 'error' }
);
// useLogsStore.getState().createLog({ message: error?.message });
}
methods: (service.methods || []).map((method) => ({ ...method, id: nanoid() })),
})),
});
})
);
}
},
updateCollection: async (id, collection, showSuccessNotification = true) => {
Expand Down
5 changes: 5 additions & 0 deletions src/app/themes/global.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export const globalStyles = globalCss({
width: '100vw',
},

// For displaying toasts on top of modals
'.nextui-backdrop': {
zIndex: '9998 !important',
},

'::-webkit-scrollbar': {
height: 2,
width: 2,
Expand Down
2 changes: 1 addition & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createWindow = (): void => {
height: 600,
width: 1000,
minHeight: 600,
minWidth: 600,
minWidth: 800,
center: true,
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
Expand Down

0 comments on commit 0cfa7a5

Please sign in to comment.