-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add project dropdown in task creation process
- Loading branch information
Showing
4 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import { IProject } from '@app/interfaces'; | ||
import { IProject, IProjectCreate } from '@app/interfaces'; | ||
import { post } from '../axios'; | ||
|
||
type Params = { | ||
name: string; | ||
tenantId: string; | ||
organizationId: string; | ||
}; | ||
export function createOrganizationProjectAPI(data: IProjectCreate) { | ||
|
||
export function createOrganizationProjectAPI(params: Params) { | ||
return post<IProject>(`/organization-projects`, params); | ||
return post<IProject>(`/organization-projects`, data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useOrganizationProjects } from '@/app/hooks'; | ||
import { IProject } from '@/app/interfaces'; | ||
import { Button, Card, InputField, Modal, Text } from 'lib/components'; | ||
import { useTranslations } from 'next-intl'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
interface ICreateProjectModalProps { | ||
open: boolean; | ||
closeModal: () => void; | ||
onSuccess?: (project: IProject) => void; | ||
} | ||
/** | ||
* A modal that allow to create a new project | ||
* | ||
* @param {Object} props - The props Object | ||
* @param {boolean} props.open - If true open the modal otherwise close the modal | ||
* @param {() => void} props.closeModal - A function to close the modal | ||
* | ||
* @returns {JSX.Element} The modal element | ||
*/ | ||
export function CreateProjectModal(props: ICreateProjectModalProps) { | ||
const t = useTranslations(); | ||
const { open, closeModal, onSuccess } = props; | ||
const { createOrganizationProject, createOrganizationProjectLoading } = useOrganizationProjects(); | ||
const [name, setName] = useState(''); | ||
|
||
const handleCreateProject = useCallback(async () => { | ||
try { | ||
const data = await createOrganizationProject({ name }); | ||
|
||
if (data) { | ||
onSuccess?.(data); | ||
} | ||
|
||
setName(''); | ||
closeModal(); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}, [closeModal, createOrganizationProject, name, onSuccess]); | ||
|
||
return ( | ||
<Modal isOpen={open} closeModal={closeModal} alignCloseIcon> | ||
<Card className=" sm:w-[33rem] w-[20rem]" shadow="custom"> | ||
<div className="flex flex-col items-center justify-between gap-8"> | ||
<Text.Heading as="h3" className="text-center"> | ||
{t('common.CREATE_PROJECT')} | ||
</Text.Heading> | ||
|
||
<div className="w-full"> | ||
<InputField | ||
name="name" | ||
autoCustomFocus | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
placeholder={'Please enter the project name'} | ||
required | ||
className="w-full" | ||
wrapperClassName=" h-full border border-blue-500" | ||
noWrapper | ||
/> | ||
</div> | ||
|
||
<div className="flex items-center justify-between w-full"> | ||
<Button | ||
disabled={createOrganizationProjectLoading} | ||
onClick={closeModal} | ||
className="h-[2.75rem]" | ||
variant="outline" | ||
> | ||
{t('common.CANCEL')} | ||
</Button> | ||
<Button | ||
disabled={createOrganizationProjectLoading} | ||
loading={createOrganizationProjectLoading} | ||
className="h-[2.75rem]" | ||
type="submit" | ||
onClick={handleCreateProject} | ||
> | ||
{t('common.CREATE')} | ||
</Button> | ||
</div> | ||
</div> | ||
</Card> | ||
</Modal> | ||
); | ||
} |