From 2cb1feedcb2ad2c8d3c3a14abb812051fc92c092 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Thu, 28 Dec 2023 18:21:27 +0530 Subject: [PATCH] Implement functionality for adding web hooks in settings Git tab (#37) * Add webhookUrl card in settings/git * Implement copy functionality * Fix form reset * Handle review changes --------- Co-authored-by: neeraj --- .../projects/project/settings/Domains.tsx | 1 + .../projects/project/settings/GitTabPanel.tsx | 77 ++++++++++++++----- .../project/settings/RepoConnectedSection.tsx | 1 + .../projects/project/settings/SetupDomain.tsx | 1 + .../projects/project/settings/WebhookCard.tsx | 62 +++++++++++++++ 5 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 packages/frontend/src/components/projects/project/settings/WebhookCard.tsx diff --git a/packages/frontend/src/components/projects/project/settings/Domains.tsx b/packages/frontend/src/components/projects/project/settings/Domains.tsx index d706a095..9a5f4428 100644 --- a/packages/frontend/src/components/projects/project/settings/Domains.tsx +++ b/packages/frontend/src/components/projects/project/settings/Domains.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { useParams, Link } from 'react-router-dom'; + import { Button, Typography } from '@material-tailwind/react'; import DomainCard from './DomainCard'; diff --git a/packages/frontend/src/components/projects/project/settings/GitTabPanel.tsx b/packages/frontend/src/components/projects/project/settings/GitTabPanel.tsx index 80e2919b..9f743bbe 100644 --- a/packages/frontend/src/components/projects/project/settings/GitTabPanel.tsx +++ b/packages/frontend/src/components/projects/project/settings/GitTabPanel.tsx @@ -1,4 +1,6 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; +import { useForm } from 'react-hook-form'; +import toast from 'react-hot-toast'; import { Button, Input, Switch, Typography } from '@material-tailwind/react'; @@ -6,10 +8,12 @@ import RepositoryList from '../../create/RepositoryList'; import RepoConnectedSection from './RepoConnectedSection'; import GitSelectionSection from './GitSelectionSection'; import { GitSelect, RepositoryDetails } from '../../../../types/project'; +import WebhookCard from './WebhookCard'; const GitTabPanel = () => { const [gitSelect, setGitSelect] = useState('none'); const [linkedRepo, setLinkedRepo] = useState(); + const [webhooksArray, setWebhooksArray] = useState>([]); const gitSelectionHandler = (git: GitSelect) => { setGitSelect(git); @@ -19,6 +23,23 @@ const GitTabPanel = () => { setLinkedRepo(repoDetails); }; + const { + register, + handleSubmit, + reset, + formState: { isSubmitSuccessful }, + } = useForm(); + + useEffect(() => { + reset(); + }, [isSubmitSuccessful]); + + const handleDelete = (index: number) => { + const newArray = webhooksArray.filter((value, idx) => idx != index); + setWebhooksArray(newArray); + toast.success('Webhook deleted successfully'); + }; + return ( <>
@@ -85,25 +106,45 @@ const GitTabPanel = () => {
-
- - Deploy webhooks - - - Webhooks configured to trigger when there is a change in a - project's build or deployment status. - -
-
- Webhook URL - -
-
- +
{ + setWebhooksArray((prevArray) => [...prevArray, data.webhookUrl]); + + toast.success('Webhook added successfully.'); + })} + > +
+ + Deploy webhooks + + + Webhooks configured to trigger when there is a change in a + project's build or deployment status. + +
+
+ Webhook URL + +
+
+ +
+
+
+ {webhooksArray?.map((webhookUrl, index) => { + return ( + handleDelete(index)} + key={index} + /> + ); + })}
); diff --git a/packages/frontend/src/components/projects/project/settings/RepoConnectedSection.tsx b/packages/frontend/src/components/projects/project/settings/RepoConnectedSection.tsx index 9f06f60c..c824f6e7 100644 --- a/packages/frontend/src/components/projects/project/settings/RepoConnectedSection.tsx +++ b/packages/frontend/src/components/projects/project/settings/RepoConnectedSection.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Button, Typography } from '@material-tailwind/react'; + import { RepositoryDetails } from '../../../../types/project'; const RepoConnectedSection = ({ diff --git a/packages/frontend/src/components/projects/project/settings/SetupDomain.tsx b/packages/frontend/src/components/projects/project/settings/SetupDomain.tsx index 5f87780c..d3facf04 100644 --- a/packages/frontend/src/components/projects/project/settings/SetupDomain.tsx +++ b/packages/frontend/src/components/projects/project/settings/SetupDomain.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useForm } from 'react-hook-form'; + import { Radio, Typography, diff --git a/packages/frontend/src/components/projects/project/settings/WebhookCard.tsx b/packages/frontend/src/components/projects/project/settings/WebhookCard.tsx new file mode 100644 index 00000000..a85b5661 --- /dev/null +++ b/packages/frontend/src/components/projects/project/settings/WebhookCard.tsx @@ -0,0 +1,62 @@ +import React, { useState } from 'react'; +import toast from 'react-hot-toast'; + +import { Button, Typography } from '@material-tailwind/react'; + +import ConfirmDialog from '../../../shared/ConfirmDialog'; + +const WebhookCard = (props: { + webhooksArray: string[]; + webhookUrl: string; + handleDelete: () => void; +}) => { + const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); + return ( +
+ {props.webhookUrl} + +
+ + +
+ + setDeleteDialogOpen((preVal) => !preVal)} + open={deleteDialogOpen} + confirmButtonTitle="Yes, Confirm delete" + handleConfirm={() => { + setDeleteDialogOpen((preVal) => !preVal); + props.handleDelete(); + }} + color="red" + > + + Are you sure you want to delete the variable{' '} + + {props.webhookUrl} + + ? + + +
+ ); +}; + +export default WebhookCard;