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'; 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); }; const repoSelectionHandler = (repoDetails: RepositoryDetails) => { 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 ( <>
Connect Git repository Create deployments for any commits pushed to your Git repository. {linkedRepo && } {!linkedRepo && (GitSelect.NONE === gitSelect ? ( ) : ( ))}
Pull request comments
Commit comments
Production branch By default, each commit pushed to the{' '} main branch initiates a production deployment. You can opt for a different branch for deployment in the settings. {!linkedRepo && (
^
This project isn't currently linked to a Git repository. To establish a production branch, please linked to an existing Git repository in the 'Connected Git Repository' section above.
)} Branch name
{ 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} /> ); })}
); }; export default GitTabPanel;