Skip to content

Commit

Permalink
add fix for dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed Nov 15, 2024
1 parent 83bd571 commit 1903e82
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .changeset/sour-dolphins-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
70 changes: 47 additions & 23 deletions packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { useAccount } from '@/hooks/account';
import { useNetwork } from '@/hooks/networks';
import type { IAddAgentProps } from '@/services/addAgent';
import { addAgent } from '@/services/addAgent';
import { Button, TextField } from '@kadena/kode-ui';
import type { IUnsignedCommand } from '@kadena/client';
import {
Button,
Dialog,
DialogContent,
DialogHeader,
TextField,
} from '@kadena/kode-ui';
import {
RightAside,
RightAsideContent,
Expand All @@ -20,45 +27,62 @@ interface IProps {
export const AddAgentForm: FC<IProps> = ({ onClose }) => {
const { activeNetwork } = useNetwork();
const { account } = useAccount();
const [openModal, setOpenModal] = useState(false);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, setError] = useState<string | null>(null);
const [transaction, setTransaction] = useState<IUnsignedCommand>();
const { register, handleSubmit } = useForm<IAddAgentProps>({
defaultValues: {
agent: '',
},
});

const onSubmit = async (data: IAddAgentProps) => {
console.log({ data });
setError(null);
try {
await addAgent(data, activeNetwork, account!);

// setIsRightAsideExpanded(false);
const tx = await addAgent(data, activeNetwork, account!);
console.log({ tx });
setTransaction(tx);
setOpenModal(true);
//onClose();
} catch (e: any) {
setError(e?.message || e);
}

// onClose();
//onClose();
};

console.log(!!transaction);

return (
<RightAside isOpen onClose={onClose}>
<form onSubmit={handleSubmit(onSubmit)}>
<RightAsideHeader label="Add Agent" />
<RightAsideContent>
<TextField
label="Agent Account"
{...register('agent', { required: true })}
/>
</RightAsideContent>
<RightAsideFooter>
<Button onPress={onClose} variant="transparent">
Cancel
</Button>
<Button type="submit">Add Agent</Button>
</RightAsideFooter>
</form>
</RightAside>
<>
<Dialog
isOpen={openModal}
onOpenChange={() => {
setOpenModal(false);
}}
>
<DialogHeader>Transaction</DialogHeader>
<DialogContent>df</DialogContent>
</Dialog>

<RightAside isOpen onClose={onClose}>
<form onSubmit={handleSubmit(onSubmit)}>
<RightAsideHeader label="Add Agent" />
<RightAsideContent>
<TextField
label="Agent Account"
{...register('agent', { required: true })}
/>
</RightAsideContent>
<RightAsideFooter>
<Button onPress={onClose} variant="transparent">
Cancel
</Button>
<Button type="submit">Add Agent</Button>
</RightAsideFooter>
</form>
</RightAside>
</>
);
};
15 changes: 1 addition & 14 deletions packages/apps/rwa-demo/src/services/addAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const addAgent = async (
network: INetwork,
account: ConnectedAccount,
) => {
const transaction = Pact.builder
return Pact.builder
.execution(
`(RWA.agent-role.add-agent (read-string 'agent) (read-keyset 'agent_guard))`,
)
Expand All @@ -49,17 +49,4 @@ export const addAgent = async (

.setNetworkId(network.networkId)
.createTransaction();

console.log({ transaction });
console.log(transaction.cmd);
console.log(JSON.parse(transaction.cmd));

// const { transactions, isReady } = await sign([transaction], [account]);
// await isReady();
// console.log(transactions);

// eslint-disable-next-line @typescript-eslint/no-floating-promises
// transactions.map(async (t) => {
// await doSubmit(t);
// });
};
4 changes: 2 additions & 2 deletions packages/libs/kode-ui/src/components/Modal/Modal.css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { style } from '../../styles';
import { style, token } from '../../styles';

export const underlayClass = style([
{
Expand All @@ -9,7 +9,7 @@ export const underlayClass = style([
inset: 0,
// TODO: Update to use token: please check docs search dialog to align
// backgroundColor: 'rgba(34, 33, 33, 0.8)',

zIndex: token('zIndex.modal'),
backdropFilter: 'blur(12px)',
},
]);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import type { Meta, StoryObj } from '@storybook/react';
import type { FC, PropsWithChildren } from 'react';
import React, { useState } from 'react';
import { Button, Stack } from './../../components';
import { Button, Dialog, DialogHeader, Stack } from './../../components';
import { SideBarBreadcrumbs } from './components/Breadcrumbs/SideBarBreadcrumbs';
import { SideBarBreadcrumbsItem } from './components/Breadcrumbs/SideBarBreadcrumbsItem';
import { LayoutProvider, useLayout } from './components/LayoutProvider';
Expand Down Expand Up @@ -68,9 +68,20 @@ const InnerLayout = () => {
useLayout();
const [hasOpenSidebar, setHasOpenSidebar] = useState(false);
const [hasOpenOtherSidebar, setHasOpenOtherSidebar] = useState(false);
const [openDialog, setOpenDialog] = useState(false);

return (
<>
{openDialog && (
<Dialog
isOpen
onOpenChange={() => {
setOpenDialog(false);
}}
>
<DialogHeader>Header of dialog</DialogHeader>
</Dialog>
)}
{isRightAsideExpanded && hasOpenSidebar && (
<RightAside
isOpen
Expand All @@ -93,7 +104,16 @@ const InnerLayout = () => {
}}
>
<RightAsideHeader label="test header" />
<RightAsideContent>content</RightAsideContent>
<RightAsideContent>
content
<Button
onPress={() => {
setOpenDialog(true);
}}
>
Open Dialog on TOP of Sidebar
</Button>
</RightAsideContent>
</RightAside>
)}
<SideBarLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const menuBackdropClass = recipe({
position: 'fixed',
inset: 0,
background: token('color.neutral.n90@alpha20'),
zIndex: token('zIndex.overlay'),
zIndex: 8000,
backdropFilter: 'blur(8px)',
opacity: 0,
willChange: 'transform, opacity',
Expand Down

0 comments on commit 1903e82

Please sign in to comment.