mirror of
https://github.com/snowball-tools/snowballtools-base.git
synced 2024-12-23 09:17:44 +00:00
Add type for outlet context used for projects data (#28)
Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
f9e4d8ebd5
commit
7d54280d5c
@ -4,27 +4,26 @@ import { useParams, Link, useOutletContext } from 'react-router-dom';
|
|||||||
import { Button, Typography } from '@material-tailwind/react';
|
import { Button, Typography } from '@material-tailwind/react';
|
||||||
|
|
||||||
import DomainCard from './DomainCard';
|
import DomainCard from './DomainCard';
|
||||||
import { DomainDetails } from '../../../../types/project';
|
import { DomainDetails, ProjectsOutletContext } from '../../../../types/project';
|
||||||
|
|
||||||
const Domains = () => {
|
const Domains = () => {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
// @ts-expect-error create context type for projects
|
const { projects } = useOutletContext<ProjectsOutletContext>();
|
||||||
const { projects } = useOutletContext();
|
|
||||||
|
|
||||||
const currProject = useMemo(() => {
|
const currProject = useMemo(() => {
|
||||||
return projects.find((data: any) => {
|
return projects.find((data) => {
|
||||||
return Number(data?.id) === Number(id);
|
return Number(data?.id) === Number(id);
|
||||||
});
|
});
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
const linkedRepo = useMemo(() => {
|
const linkedRepo = useMemo(() => {
|
||||||
return currProject.repositories.find(
|
return currProject?.repositories.find(
|
||||||
(repo: any) => repo.id === Number(currProject?.repositoryId),
|
(repo: any) => repo.id === Number(currProject?.repositoryId),
|
||||||
);
|
);
|
||||||
}, [currProject]);
|
}, [currProject]);
|
||||||
|
|
||||||
const domains = currProject.deployments
|
const domains = currProject?.deployments
|
||||||
.filter((deployment: any) => {
|
.filter((deployment: any) => {
|
||||||
return deployment.domain != null;
|
return deployment.domain != null;
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { useFieldArray, useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
|
import { useOutletContext, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Typography,
|
Typography,
|
||||||
@ -13,9 +14,12 @@ import {
|
|||||||
|
|
||||||
import AddEnvironmentVariableRow from './AddEnvironmentVariableRow';
|
import AddEnvironmentVariableRow from './AddEnvironmentVariableRow';
|
||||||
import DisplayEnvironmentVariables from './DisplayEnvironmentVariables';
|
import DisplayEnvironmentVariables from './DisplayEnvironmentVariables';
|
||||||
import { EnvironmentVariable, Environments } from '../../../../types/project';
|
import {
|
||||||
|
EnvironmentVariable,
|
||||||
|
Environments,
|
||||||
|
ProjectsOutletContext,
|
||||||
|
} from '../../../../types/project';
|
||||||
import HorizontalLine from '../../../HorizontalLine';
|
import HorizontalLine from '../../../HorizontalLine';
|
||||||
import { useOutletContext, useParams } from 'react-router-dom';
|
|
||||||
|
|
||||||
export type EnvironmentVariablesFormValues = {
|
export type EnvironmentVariablesFormValues = {
|
||||||
variables: {
|
variables: {
|
||||||
@ -32,11 +36,10 @@ export type EnvironmentVariablesFormValues = {
|
|||||||
export const EnvironmentVariablesTabPanel = () => {
|
export const EnvironmentVariablesTabPanel = () => {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
// @ts-expect-error create context type for projects
|
const { projects } = useOutletContext<ProjectsOutletContext>();
|
||||||
const { projects } = useOutletContext();
|
|
||||||
|
|
||||||
const currProject = useMemo(() => {
|
const currProject = useMemo(() => {
|
||||||
return projects.find((data: any) => Number(data.id) === Number(id));
|
return projects.find((data) => Number(data.id) === Number(id));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -72,7 +75,7 @@ export const EnvironmentVariablesTabPanel = () => {
|
|||||||
}, [isSubmitSuccessful, reset]);
|
}, [isSubmitSuccessful, reset]);
|
||||||
|
|
||||||
const getEnvironmentVariable = useCallback((environment: Environments) => {
|
const getEnvironmentVariable = useCallback((environment: Environments) => {
|
||||||
return (currProject.environmentVariables as EnvironmentVariable[]).filter(
|
return (currProject?.environmentVariables as EnvironmentVariable[]).filter(
|
||||||
(item) => item.environments.includes(environment),
|
(item) => item.environments.includes(environment),
|
||||||
);
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -5,10 +5,10 @@ import { Link } from 'react-router-dom';
|
|||||||
import { Button, Typography, Chip } from '@material-tailwind/react';
|
import { Button, Typography, Chip } from '@material-tailwind/react';
|
||||||
|
|
||||||
import ProjectCard from '../components/projects/ProjectCard';
|
import ProjectCard from '../components/projects/ProjectCard';
|
||||||
|
import { ProjectsOutletContext } from '../types/project';
|
||||||
|
|
||||||
const Projects = () => {
|
const Projects = () => {
|
||||||
// @ts-expect-error create context type for projects
|
const { projects } = useOutletContext<ProjectsOutletContext>();
|
||||||
const { projects } = useOutletContext();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -5,6 +5,7 @@ import { Button, Typography } from '@material-tailwind/react';
|
|||||||
|
|
||||||
import HorizontalLine from '../../components/HorizontalLine';
|
import HorizontalLine from '../../components/HorizontalLine';
|
||||||
import ProjectTabs from '../../components/projects/project/ProjectTabs';
|
import ProjectTabs from '../../components/projects/project/ProjectTabs';
|
||||||
|
import { ProjectsOutletContext } from '../../types/project';
|
||||||
|
|
||||||
const getProject = (projects: any, id: number) => {
|
const getProject = (projects: any, id: number) => {
|
||||||
return projects.find((project: any) => {
|
return projects.find((project: any) => {
|
||||||
@ -16,8 +17,7 @@ const Project = () => {
|
|||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
// @ts-expect-error create context type for projects
|
const { projects } = useOutletContext<ProjectsOutletContext>();
|
||||||
const { projects } = useOutletContext();
|
|
||||||
|
|
||||||
const project = useMemo(
|
const project = useMemo(
|
||||||
() => getProject(projects, Number(id)),
|
() => getProject(projects, Number(id)),
|
||||||
|
@ -4,10 +4,10 @@ import { Link, useOutletContext } from 'react-router-dom';
|
|||||||
import { Button, Typography, Chip } from '@material-tailwind/react';
|
import { Button, Typography, Chip } from '@material-tailwind/react';
|
||||||
|
|
||||||
import ProjectCard from '../../components/projects/ProjectCard';
|
import ProjectCard from '../../components/projects/ProjectCard';
|
||||||
|
import { ProjectsOutletContext } from '../../types/project';
|
||||||
|
|
||||||
const Projects = () => {
|
const Projects = () => {
|
||||||
// @ts-expect-error create context type for projects
|
const { projects } = useOutletContext<ProjectsOutletContext>();
|
||||||
const { projects } = useOutletContext();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -16,6 +16,7 @@ export interface ProjectDetails {
|
|||||||
branch: string;
|
branch: string;
|
||||||
};
|
};
|
||||||
repositoryId: number;
|
repositoryId: number;
|
||||||
|
repositories: RepositoryDetails[];
|
||||||
members: MemberPermission[];
|
members: MemberPermission[];
|
||||||
ownerId: number;
|
ownerId: number;
|
||||||
environmentVariables: EnvironmentVariable[];
|
environmentVariables: EnvironmentVariable[];
|
||||||
@ -102,3 +103,7 @@ export interface Member {
|
|||||||
email: string;
|
email: string;
|
||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ProjectsOutletContext {
|
||||||
|
projects: ProjectDetails[];
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user