Skip to content

Commit 2d9a991

Browse files
committed
fix(types): resolve TS errors in Sidebar, Repositories and UserList
1 parent 2ccf4d5 commit 2d9a991

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

src/types/images.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.png' {
2+
const url: string;
3+
export default url;
4+
}

src/ui/components/Navbars/DashboardNavbarLinks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const DashboardNavbarLinks: React.FC = () => {
5252
const logout = async () => {
5353
try {
5454
const response = await axios.post(
55-
`${import.meta.env.VITE_API_URI || 'http://localhost:3000'}/api/auth/logout`,
55+
`${process.env.VITE_API_URI || 'http://localhost:3000'}/api/auth/logout`,
5656
{},
5757
{
5858
withCredentials: true,

src/ui/components/Sidebar/Sidebar.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ interface SidebarProps {
2323
open: boolean;
2424
}
2525

26-
const Sidebar: React.FC<SidebarProps> = (props) => {
26+
const Sidebar: React.FC<SidebarProps> = ({
27+
color,
28+
logo,
29+
routes,
30+
background,
31+
rtlActive,
32+
open,
33+
handleDrawerToggle,
34+
}) => {
2735
const classes = useStyles();
2836

29-
const activeRoute = (routeName: string): boolean => {
30-
return window.location.href.indexOf(routeName) > -1;
31-
};
32-
33-
const { color, logo, routes, background, rtlActive, open, handleDrawerToggle } = props;
37+
const activeRoute = (routeName: string) => window.location.href.includes(routeName);
3438

3539
const links = (
3640
<List className={classes.list}>
@@ -39,14 +43,13 @@ const Sidebar: React.FC<SidebarProps> = (props) => {
3943
const listItemClasses = classNames({
4044
[` ${classes[color]}`]: activeRoute(prop.layout + prop.path),
4145
});
42-
4346
const whiteFontClasses = classNames({
4447
[` ${classes.whiteFont}`]: activeRoute(prop.layout + prop.path),
4548
});
4649

47-
if (!prop.visible) {
48-
return <div key={key}></div>;
49-
}
50+
if (!prop.visible) return <div key={key} />;
51+
52+
const IconComponent = prop.icon as React.ElementType;
5053

5154
return (
5255
<NavLink
@@ -65,7 +68,7 @@ const Sidebar: React.FC<SidebarProps> = (props) => {
6568
{prop.icon}
6669
</Icon>
6770
) : (
68-
<prop.icon
71+
<IconComponent
6972
className={classNames(classes.itemIcon, whiteFontClasses, {
7073
[classes.itemIconRTL]: rtlActive,
7174
})}
@@ -90,10 +93,10 @@ const Sidebar: React.FC<SidebarProps> = (props) => {
9093
<a style={{ textDecoration: 'none' }} href='/dashboard/repo'>
9194
<div style={{ textAlign: 'center' }}>
9295
<img
93-
style={{ verticalAlign: 'middle', filter: 'brightness(0) invert(1)' }}
94-
width={'105px'}
9596
src={logo}
9697
alt='logo'
98+
width={105}
99+
style={{ verticalAlign: 'middle', filter: 'brightness(0) invert(1)' }}
97100
/>
98101
</div>
99102
</a>

src/ui/views/Login/Login.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface LoginResponse {
2121
password: string;
2222
}
2323

24-
const loginUrl = `${import.meta.env.VITE_API_URI}/api/auth/login`;
24+
const loginUrl = `${process.env.VITE_API_URI}/api/auth/login`;
2525

2626
const Login: React.FC = () => {
2727
const navigate = useNavigate();
@@ -41,7 +41,7 @@ const Login: React.FC = () => {
4141
}
4242

4343
function handleOIDCLogin(): void {
44-
window.location.href = `${import.meta.env.VITE_API_URI}/api/auth/oidc`;
44+
window.location.href = `${process.env.VITE_API_URI}/api/auth/oidc`;
4545
}
4646

4747
function handleSubmit(event: FormEvent): void {

src/ui/views/PushDetails/components/AttestationView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Checkbox from '@material-ui/core/Checkbox';
1111
import { withStyles } from '@material-ui/core/styles';
1212
import { green } from '@material-ui/core/colors';
1313
import { getURLShortener } from '../../../services/config';
14+
import { AttestationViewProps } from '../attestation.types';
1415

1516
const StyledFormControlLabel = withStyles({
1617
root: {

src/ui/views/RepoList/Components/RepoOverview.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ const Repositories: React.FC<RepositoriesProps> = (props) => {
3232

3333
useEffect(() => {
3434
getGitHubRepository();
35-
}, [props.data.project, props.data.name]);
35+
}, [props.data?.project, props.data?.name]);
3636

3737
const getGitHubRepository = async () => {
3838
await axios
39-
.get(`https://api.github.com/repos/${props.data.project}/${props.data.name}`)
39+
.get(`https://api.github.com/repos/${props.data?.project}/${props.data?.name}`)
4040
.then((res) => {
4141
setGitHub(res.data);
4242
})
4343
.catch((error) => {
4444
setErrorMessage(
45-
`Error fetching GitHub repository ${props.data.project}/${props.data.name}: ${error}`,
45+
`Error fetching GitHub repository ${props.data?.project}/${props.data?.name}: ${error}`,
4646
);
4747
setSnackbarOpen(true);
4848
});
@@ -55,9 +55,9 @@ const Repositories: React.FC<RepositoriesProps> = (props) => {
5555
<TableRow>
5656
<TableCell>
5757
<div style={{ padding: '15px' }}>
58-
<a href={`/dashboard/repo/${props.data.name}`}>
58+
<a href={`/dashboard/repo/${props.data?.name}`}>
5959
<span style={{ fontSize: '17px' }}>
60-
{props.data.project}/{props.data.name}
60+
{props.data?.project}/{props.data?.name}
6161
</span>
6262
</a>
6363
{github.parent && (
@@ -105,12 +105,12 @@ const Repositories: React.FC<RepositoriesProps> = (props) => {
105105
)}
106106
<GridItem>
107107
<PeopleIcon size='small' />{' '}
108-
<span style={{ marginLeft: '5px' }}>{props.data.users?.canPush?.length || 0}</span>
108+
<span style={{ marginLeft: '5px' }}>{props.data?.users?.canPush?.length || 0}</span>
109109
</GridItem>
110110
<GridItem>
111111
<CodeReviewIcon size='small' />{' '}
112112
<span style={{ marginLeft: '5px' }}>
113-
{props.data.users?.canAuthorise?.length || 0}
113+
{props.data?.users?.canAuthorise?.length || 0}
114114
</span>
115115
</GridItem>
116116
{(github.created_at || github.updated_at || github.pushed_at) && (

src/ui/views/RepoList/repositories.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface RepositoriesProps {
2-
data: {
2+
data?: {
33
project: string;
44
name: string;
55
proxyURL: string;

src/ui/views/UserList/Components/UserList.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ import { getUsers } from '../../../services/user';
1616
import Pagination from '../../../components/Pagination/Pagination';
1717
import { CloseRounded, Check, KeyboardArrowRight } from '@material-ui/icons';
1818
import Search from '../../../components/Search/Search';
19-
20-
interface User {
21-
username: string;
22-
displayName?: string;
23-
title?: string;
24-
email?: string;
25-
gitAccount?: string;
26-
admin?: boolean;
27-
}
19+
import { UserData } from '../../../../types/models';
2820

2921
interface UserListProps {
3022
[key: string]: any;
@@ -34,7 +26,7 @@ const useStyles = makeStyles(styles as any);
3426

3527
const UserList: React.FC<UserListProps> = (props) => {
3628
const classes = useStyles();
37-
const [data, setData] = useState<User[]>([]);
29+
const [data, setData] = useState<UserData[]>([]);
3830
const [, setAuth] = useState<boolean>(true);
3931
const [isLoading, setIsLoading] = useState<boolean>(false);
4032
const [isError, setIsError] = useState<boolean>(false);

0 commit comments

Comments
 (0)