-
Notifications
You must be signed in to change notification settings - Fork 272
/
OwnersPage.tsx
51 lines (39 loc) · 1 KB
/
OwnersPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as React from 'react';
import { Link } from 'react-router';
import { IOwner } from '../../types';
import { url } from '../../util';
import OwnerInformation from './OwnerInformation';
import PetsTable from './PetsTable';
interface IOwnersPageProps {
params?: { ownerId?: string };
}
interface IOwnerPageState {
owner?: IOwner;
}
export default class OwnersPage extends React.Component<IOwnersPageProps, IOwnerPageState> {
constructor() {
super();
this.state = {};
}
componentDidMount() {
const { params } = this.props;
if (params && params.ownerId) {
const fetchUrl = url(`/api/owner/${params.ownerId}`);
fetch(fetchUrl)
.then(response => response.json())
.then(owner => this.setState({ owner }));
}
}
render() {
const { owner } = this.state;
if (!owner) {
return <h2>No Owner loaded</h2>;
}
return (
<span>
<OwnerInformation owner={owner} />
<PetsTable owner={owner} />
</span>
);
}
}