Commit c1299091859b926d3a91d1cbdce2b25a4092b5e3
1 parent
524281ec
OJT21-61: Add log component and logs mock request
Showing
5 changed files
with
72 additions
and
1 deletions
components/log.js
0 → 100644
... | ... | @@ -2,12 +2,28 @@ import { rest } from 'msw' |
2 | 2 | |
3 | 3 | export const handlers = [ |
4 | 4 | // sample |
5 | - rest.get('*/', (req, res, ctx) => { | |
5 | + rest.get('/', (req, res, ctx) => { | |
6 | 6 | ctx.status = 200 |
7 | 7 | return res( |
8 | 8 | ctx.json({ |
9 | 9 | sample: 'this is a sample' |
10 | 10 | }) |
11 | 11 | ) |
12 | + }), | |
13 | + rest.get('https://api/logs', (req, res, ctx) => { | |
14 | + console.log('yooooooo') | |
15 | + ctx.status = 200 | |
16 | + return res( | |
17 | + ctx.json({ | |
18 | + logs: [ | |
19 | + { | |
20 | + ticket: 'SAM-PLE', | |
21 | + details: | |
22 | + 'Today ...................................................................................', | |
23 | + hours: '5' | |
24 | + } | |
25 | + ] | |
26 | + }) | |
27 | + ) | |
12 | 28 | }) |
13 | 29 | ] | ... | ... |
mocks/server.js
0 → 100644
1 | 1 | import 'tailwindcss/tailwind.css' |
2 | 2 | |
3 | +if (process.env.NODE_ENV === 'development') { | |
4 | + if (typeof window === 'undefined') { | |
5 | + const { server } = require('../mocks/server') | |
6 | + server.listen() | |
7 | + console.log('SERVER STARTED') | |
8 | + } else { | |
9 | + const { worker } = require('../mocks/browser') | |
10 | + worker.start() | |
11 | + console.log('WORKER STARTED') | |
12 | + } | |
13 | +} | |
14 | + | |
3 | 15 | function MyApp ({ Component, pageProps }) { |
4 | 16 | return <Component {...pageProps} /> |
5 | 17 | } | ... | ... |
pages/logs.js
0 → 100644
1 | +import Log from '../components/log.js' | |
2 | +const axios = require('axios') | |
3 | + | |
4 | +function Logs ({ logs }) { | |
5 | + return ( | |
6 | + <div> | |
7 | + {logs.logs.map((log) => ( | |
8 | + <Log log={log} /> | |
9 | + ))} | |
10 | + </div> | |
11 | + ) | |
12 | +} | |
13 | + | |
14 | +export async function getStaticProps () { | |
15 | + let logs = {} | |
16 | + try { | |
17 | + const response = await axios.get('https://api/logs') | |
18 | + console.log(response.data) | |
19 | + logs = response.data | |
20 | + } catch (error) { | |
21 | + console.error(error) | |
22 | + } | |
23 | + return { | |
24 | + props: { | |
25 | + logs | |
26 | + } | |
27 | + } | |
28 | +} | |
29 | + | |
30 | +export default Logs | ... | ... |