Skip to content

Commit

Permalink
fix(ms2/process-creation-button): open modal on meta+enter
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeTrost committed Nov 27, 2024
1 parent c216e4f commit 56ca853
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/management-system-v2/components/process-creation-button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use client';

import React, { ComponentProps, ReactNode, useState } from 'react';
import { Button } from 'antd';
import type { ButtonProps, ModalProps } from 'antd';
Expand All @@ -13,17 +11,17 @@ import { spaceURL } from '@/lib/utils';
export const ProcessCreationModal: React.FC<
Partial<ComponentProps<typeof ProcessModal>> & {
open: boolean;
close: () => void;
setOpen: (open: boolean) => void;
customAction?: (values: { name: string; description: string }) => Promise<any>;
}
> = (props) => {
> = ({ open, setOpen, customAction, ...props }) => {
const router = useRouter();
const environment = useEnvironment();
const folderId = useParams<{ folderId: string }>().folderId ?? '';

const createNewProcess = async (values: { name: string; description: string }[]) => {
// Invoke the custom handler otherwise use the default server action.
const process = await (props.customAction?.(values[0]) ??
const process = await (customAction?.(values[0]) ??
addProcesses(
values.map((value) => ({ ...value, folderId })),
environment.spaceId,
Expand All @@ -33,7 +31,7 @@ export const ProcessCreationModal: React.FC<
return process;
}

props.close();
setOpen(false);

if (process && 'id' in process) {
router.push(spaceURL(environment, `/processes/${process.id}`));
Expand All @@ -46,8 +44,8 @@ export const ProcessCreationModal: React.FC<
'process-list',
['control+enter', 'new'],
() => {
if (!props.open) {
props.close();
if (!open) {
setOpen(true);
}
},
{
Expand All @@ -59,10 +57,10 @@ export const ProcessCreationModal: React.FC<
return (
<ProcessModal
{...props}
open={props.open}
open={open}
title="Create Process"
okText="Create"
onCancel={props.close}
onCancel={() => setOpen(false)}
onSubmit={createNewProcess}
/>
);
Expand Down Expand Up @@ -97,7 +95,7 @@ const ProcessCreationButton: React.FC<ProcessCreationButtonProps> = ({
)}
<ProcessCreationModal
open={isProcessModalOpen}
close={() => setIsProcessModalOpen(false)}
setOpen={setIsProcessModalOpen}
customAction={customAction}
modalProps={modalProps}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/management-system-v2/components/processes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ const Processes = ({
/>
<ProcessCreationModal
open={openCreateProcessModal}
close={() => setOpenCreateProcessModal(false)}
setOpen={setOpenCreateProcessModal}
modalProps={{
onCancel: deleteCreateProcessSearchParams,
onOk: deleteCreateProcessSearchParams,
Expand Down

0 comments on commit 56ca853

Please sign in to comment.