forked from cerc-io/snowballtools-base
Implement functionality to delete domain (#59)
* Implement functionality to delete domain * Remove redirectToId from frontend --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
committed by
Ashwin Phatak
co-authored by
neeraj
parent
3a7f16467e
commit
1d58beb2ec
@@ -15,6 +15,7 @@ import {
|
||||
import { ProjectDetails, RepositoryDetails } from '../../../../types/project';
|
||||
import ConfirmDialog from '../../../shared/ConfirmDialog';
|
||||
import EditDomainDialog from './EditDomainDialog';
|
||||
import { useGQLClient } from '../../../../context/GQLClientContext';
|
||||
|
||||
enum RefreshStatus {
|
||||
IDLE,
|
||||
@@ -51,6 +52,19 @@ const DomainCard = ({
|
||||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
||||
|
||||
const client = useGQLClient();
|
||||
|
||||
const deleteDomain = async () => {
|
||||
const { deleteDomain } = await client.deleteDomain(domain.id);
|
||||
|
||||
if (deleteDomain) {
|
||||
onUpdate();
|
||||
toast.success(`Domain ${domain.name} deleted successfully`);
|
||||
} else {
|
||||
toast.error(`Error deleting domain ${domain.name}`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex justify-between py-3">
|
||||
@@ -109,8 +123,8 @@ const DomainCard = ({
|
||||
open={deleteDialogOpen}
|
||||
confirmButtonTitle="Yes, Delete domain"
|
||||
handleConfirm={() => {
|
||||
deleteDomain();
|
||||
setDeleteDialogOpen((preVal) => !preVal);
|
||||
toast.success(`Domain "${domain.name}" has been deleted`);
|
||||
}}
|
||||
color="red"
|
||||
>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { useParams, Link, useOutletContext } from 'react-router-dom';
|
||||
import { Domain } from 'gql-client';
|
||||
|
||||
import { Button, Typography } from '@material-tailwind/react';
|
||||
|
||||
import DomainCard from './DomainCard';
|
||||
import { ProjectSearchOutletContext } from '../../../../types/project';
|
||||
import { useGQLClient } from '../../../../context/GQLClientContext';
|
||||
import { Domain } from 'gql-client';
|
||||
import repositories from '../../../../assets/repositories.json';
|
||||
|
||||
const Domains = () => {
|
||||
const { id } = useParams();
|
||||
@@ -22,16 +23,6 @@ const Domains = () => {
|
||||
});
|
||||
}, [id, projects]);
|
||||
|
||||
// TODO: Use github API for getting linked repository
|
||||
const linkedRepo = {
|
||||
id: 3,
|
||||
title: 'project-103',
|
||||
updatedAt: '2023-12-21T04:20:00',
|
||||
user: 'charlie',
|
||||
private: false,
|
||||
branch: ['main', 'prod', 'test'],
|
||||
};
|
||||
|
||||
const fetchDomains = async () => {
|
||||
if (currentProject === undefined) {
|
||||
return;
|
||||
@@ -62,7 +53,8 @@ const Domains = () => {
|
||||
domains={domains}
|
||||
domain={domain}
|
||||
key={domain.id}
|
||||
repo={linkedRepo!}
|
||||
// TODO: Use github API for getting linked repository
|
||||
repo={repositories[0]!}
|
||||
project={currentProject!}
|
||||
onUpdate={fetchDomains}
|
||||
/>
|
||||
|
||||
@@ -63,7 +63,7 @@ const EditDomainDialog = ({
|
||||
}, [domains, domain]);
|
||||
|
||||
const isDisableDropdown = useMemo(() => {
|
||||
return domainRedirectedFrom?.redirectTo?.id !== undefined;
|
||||
return domainRedirectedFrom !== undefined;
|
||||
}, [domain, domains]);
|
||||
|
||||
const {
|
||||
|
||||
Reference in New Issue
Block a user