Skip to content

Commit b7d632d

Browse files
Mikadowsangristan
authored andcommitted
refactor: add optional navigation button on header
1 parent 0b2c421 commit b7d632d

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

src/components/Benchmarks/BenchmarkDetail.tsx

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import { Link, Redirect } from 'react-router-dom';
2+
import { Redirect } from 'react-router-dom';
33
import { BenchmarkServices } from '../../api/BenchmarkServices';
44
import Header from '../Page/Header';
55
import Page from '../Page/Page';
@@ -27,29 +27,17 @@ const BenchmarkDetail = (props) => {
2727
});
2828
}, [setBenchmark, props.match.params.id]);
2929

30-
if (benchmark === '') {
30+
if (benchmark === ''|| undefined) {
3131
return <Redirect to="/404" />;
3232
}
3333

3434
return (
3535
<Page>
36-
<Header title="Dashboard" />
37-
<header className="bg-white shadow">
38-
<div className="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8 flex justify-between">
39-
<h1 className="text-3xl font-bold text-gray-900">
40-
{
41-
// @ts-ignore
42-
benchmark === undefined ? '' : benchmark.title
43-
}
44-
</h1>
45-
<Link
46-
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full"
47-
to="/benchmarks"
48-
>
49-
Back
50-
</Link>
51-
</div>
52-
</header>
36+
<Header title={
37+
// @ts-ignore
38+
benchmark === undefined ? '' : benchmark.title}
39+
button='Back' navTo='/benchmarks'
40+
/>
5341
<div className="flex p-4">
5442
<div className="flex-1 mx-auto border-4 border-dashed border-gray-200 rounded-lg h-96">
5543
<div className="pl-8 pr-8">

src/components/Benchmarks/Benchmarks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class Benchmarks extends React.Component<
103103
render() {
104104
return (
105105
<Page>
106-
<Header title="Benchmarks" />
106+
<Header title="Benchmarks" button="Create" navTo="/benchmarks/create"/>
107107
<div className="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
108108
<div className="flex flex-col">
109109
<div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">

src/components/Benchmarks/CreateBenchmark.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ export class CreateBenchmark extends React.Component<
4545
render() {
4646
return (
4747
<Page>
48-
<Header title="Dashboard" />
49-
<header className="bg-white shadow">
50-
<div className="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8 flex justify-between">
51-
<h1 className="text-3xl font-bold text-gray-900">
52-
Create benchmark
53-
</h1>
54-
</div>
55-
</header>
48+
<Header title="Create benchmark" />
5649
<div className="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
5750
<form className="w-full max-w-lg" onSubmit={this.onSubmit}>
5851
<div className="flex flex-wrap -mx-3 mb-6">

src/components/Page/Header.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
import {Link} from "react-router-dom";
2+
import React from "react";
3+
14
interface HeaderProps {
25
title: string;
6+
button?: string;
7+
navTo?: string;
38
}
49

5-
const Header: React.FC<HeaderProps> = ({ title }) => {
6-
return (
10+
const Header: React.FC<HeaderProps> = ({ title, button, navTo}) => {
11+
const isButtonNeeded = button !== undefined && navTo !== undefined;
12+
13+
return (
714
<header className="bg-white shadow">
8-
<div className="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
15+
<div className="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8 flex justify-between">
916
<h1 className="text-3xl font-bold text-gray-900">{title}</h1>
17+
{isButtonNeeded?
18+
<Link
19+
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full"
20+
to={navTo !== undefined ? navTo : '/500'}
21+
>
22+
{button}
23+
</Link>
24+
: <></>}
1025
</div>
26+
1127
</header>
28+
1229
);
1330
};
1431

0 commit comments

Comments
 (0)