[4/n][project settings ui] GitTabPanel cleanup (#26)
This commit is contained in:
commit
e4c39e0955
@ -1,18 +1,15 @@
|
|||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useOutletContext } from 'react-router-dom';
|
import { useOutletContext } from 'react-router-dom';
|
||||||
import { SubmitHandler, useForm } from 'react-hook-form';
|
import { SubmitHandler, useForm } from 'react-hook-form';
|
||||||
import toast from 'react-hot-toast';
|
|
||||||
|
|
||||||
import {
|
import WebhookCard from 'components/projects/project/settings/WebhookCard';
|
||||||
Button,
|
|
||||||
Input,
|
|
||||||
Switch,
|
|
||||||
Typography,
|
|
||||||
} from '@snowballtools/material-tailwind-react-fork';
|
|
||||||
|
|
||||||
import WebhookCard from '../../../../../components/projects/project/settings/WebhookCard';
|
|
||||||
import { useGQLClient } from '../../../../../context/GQLClientContext';
|
import { useGQLClient } from '../../../../../context/GQLClientContext';
|
||||||
import { OutletContextType } from '../../../../../types/types';
|
import { OutletContextType } from '../../../../../types';
|
||||||
|
import { Button } from 'components/shared/Button';
|
||||||
|
import { Input } from 'components/shared/Input';
|
||||||
|
import { Switch } from 'components/shared/Switch';
|
||||||
|
import { Heading } from 'components/shared/Heading';
|
||||||
|
import { useToast } from 'components/shared/Toast';
|
||||||
|
|
||||||
type UpdateProdBranchValues = {
|
type UpdateProdBranchValues = {
|
||||||
prodBranch: string;
|
prodBranch: string;
|
||||||
@ -24,8 +21,12 @@ type UpdateWebhooksValues = {
|
|||||||
|
|
||||||
const GitTabPanel = () => {
|
const GitTabPanel = () => {
|
||||||
const client = useGQLClient();
|
const client = useGQLClient();
|
||||||
|
const { toast } = useToast();
|
||||||
const { project, onUpdate } = useOutletContext<OutletContextType>();
|
const { project, onUpdate } = useOutletContext<OutletContextType>();
|
||||||
|
|
||||||
|
const [pullRequestComments, updatePullRequestComments] = useState(true);
|
||||||
|
const [commitComments, updateCommitComments] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register: registerProdBranch,
|
register: registerProdBranch,
|
||||||
handleSubmit: handleSubmitProdBranch,
|
handleSubmit: handleSubmitProdBranch,
|
||||||
@ -45,9 +46,19 @@ const GitTabPanel = () => {
|
|||||||
|
|
||||||
if (updateProject) {
|
if (updateProject) {
|
||||||
await onUpdate();
|
await onUpdate();
|
||||||
toast.success('Production branch upadated successfully');
|
toast({
|
||||||
|
id: 'prod_branch_updated',
|
||||||
|
title: 'Production branch updated successfully',
|
||||||
|
variant: 'success',
|
||||||
|
onDismiss() {},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error updating production branch');
|
toast({
|
||||||
|
id: 'prod_branch_update_failed',
|
||||||
|
title: 'Error updating production branch',
|
||||||
|
variant: 'error',
|
||||||
|
onDismiss() {},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[project],
|
[project],
|
||||||
@ -72,9 +83,19 @@ const GitTabPanel = () => {
|
|||||||
|
|
||||||
if (updateProject) {
|
if (updateProject) {
|
||||||
await onUpdate();
|
await onUpdate();
|
||||||
toast.success('Webhook added successfully');
|
toast({
|
||||||
|
id: 'webhook_added',
|
||||||
|
title: 'Webhook added successfully',
|
||||||
|
variant: 'success',
|
||||||
|
onDismiss() {},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error adding webhook');
|
toast({
|
||||||
|
id: 'webhook_add_failed',
|
||||||
|
title: 'Error adding webhook',
|
||||||
|
variant: 'error',
|
||||||
|
onDismiss() {},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resetWebhooks();
|
resetWebhooks();
|
||||||
@ -96,80 +117,107 @@ const GitTabPanel = () => {
|
|||||||
|
|
||||||
if (updateProject) {
|
if (updateProject) {
|
||||||
await onUpdate();
|
await onUpdate();
|
||||||
toast.success('Webhook deleted successfully');
|
toast({
|
||||||
|
id: 'webhook_deleted',
|
||||||
|
title: 'Webhook deleted successfully',
|
||||||
|
variant: 'success',
|
||||||
|
onDismiss() {},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error deleting webhook');
|
toast({
|
||||||
|
id: 'webhook_delete_failed',
|
||||||
|
title: 'Error deleting webhook',
|
||||||
|
variant: 'error',
|
||||||
|
onDismiss() {},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="flex-col justify-start items-start gap-6 inline-flex">
|
||||||
<div className="mb-2 p-2">
|
<div className="self-stretch space-y-3 px-2">
|
||||||
<Typography variant="h6" className="text-black">
|
<Heading className="text-sky-950 text-lg font-medium leading-normal">
|
||||||
Git repository
|
Git repository
|
||||||
</Typography>
|
</Heading>
|
||||||
|
|
||||||
<div className="flex justify-between mt-4">
|
<div className="flex justify-between mt-4">
|
||||||
<div>
|
<div>
|
||||||
<Typography variant="small">Pull request comments</Typography>
|
<p className="text-slate-600 text-sm font-normal leading-tight">
|
||||||
|
Pull request comments
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Switch defaultChecked />
|
<Switch
|
||||||
|
checked={pullRequestComments}
|
||||||
|
onChange={() => updatePullRequestComments(!pullRequestComments)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<div>
|
<div>
|
||||||
<Typography variant="small">Commit comments</Typography>
|
<p className="text-slate-600 text-sm font-normal leading-tight">
|
||||||
|
Commit comments
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Switch />
|
<Switch
|
||||||
|
checked={commitComments}
|
||||||
|
onChange={() => updateCommitComments(!commitComments)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={handleSubmitProdBranch(updateProdBranchHandler)}>
|
<form
|
||||||
<div className="mb-2 p-2">
|
onSubmit={handleSubmitProdBranch(updateProdBranchHandler)}
|
||||||
<Typography variant="h6" className="text-black">
|
className="space-y-3 px-2"
|
||||||
Production branch
|
>
|
||||||
</Typography>
|
<Heading className="text-sky-950 text-lg font-medium leading-normal">
|
||||||
<Typography variant="small">
|
Production branch
|
||||||
By default, each commit pushed to the{' '}
|
</Heading>
|
||||||
<span className="font-bold">{project.prodBranch}</span> branch
|
<p className="text-slate-600 text-sm font-normal leading-tight">
|
||||||
initiates a production deployment. You can opt for a different
|
By default, each commit pushed to the{' '}
|
||||||
branch for deployment in the settings.
|
<span className="font-bold">{project.prodBranch}</span> branch
|
||||||
</Typography>
|
initiates a production deployment. You can opt for a different branch
|
||||||
<Typography variant="small">Branch name</Typography>
|
for deployment in the settings.
|
||||||
<Input {...registerProdBranch('prodBranch')} />
|
</p>
|
||||||
<Button size="sm" className="mt-1" type="submit">
|
<p className="text-slate-600 text-sm font-normal leading-tight">
|
||||||
Save
|
Branch name
|
||||||
</Button>
|
</p>
|
||||||
</div>
|
<Input {...registerProdBranch('prodBranch')} />
|
||||||
|
<Button size="md" variant="primary">
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form onSubmit={handleSubmitWebhooks(updateWebhooksHandler)}>
|
<form
|
||||||
<div className="mb-2 p-2">
|
onSubmit={handleSubmitWebhooks(updateWebhooksHandler)}
|
||||||
<Typography variant="h6" className="text-black">
|
className="space-y-3 px-2"
|
||||||
Deploy webhooks
|
>
|
||||||
</Typography>
|
<Heading className="text-sky-950 text-lg font-medium leading-normal">
|
||||||
<Typography variant="small">
|
Deploy webhooks
|
||||||
Webhooks configured to trigger when there is a change in a
|
</Heading>
|
||||||
project's build or deployment status.
|
<p className="text-slate-600 text-sm font-normal leading-tight">
|
||||||
</Typography>
|
{' '}
|
||||||
<div className="flex gap-1">
|
Webhooks configured to trigger when there is a change in a
|
||||||
<div className="grow">
|
project's build or deployment status.
|
||||||
<Typography variant="small">Webhook URL</Typography>
|
</p>
|
||||||
<Input {...registerWebhooks('webhookUrl')} />
|
<div className="flex gap-1">
|
||||||
</div>
|
<div className="grow">
|
||||||
<div className="self-end">
|
<p className="text-slate-600 text-sm font-normal leading-tight">
|
||||||
<Button size="sm" type="submit">
|
Webhook URL
|
||||||
Save
|
</p>
|
||||||
</Button>
|
<Input {...registerWebhooks('webhookUrl')} />
|
||||||
</div>
|
</div>
|
||||||
|
<div className="self-end">
|
||||||
|
<Button size="sm" type="submit">
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div className="mb-2 p-2">
|
<div className="space-y-3 px-2">
|
||||||
{project.webhooks.map((webhookUrl, index) => {
|
{project.webhooks.map((webhookUrl, index) => {
|
||||||
return (
|
return (
|
||||||
<WebhookCard
|
<WebhookCard
|
||||||
@ -180,7 +228,7 @@ const GitTabPanel = () => {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user