-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a251cf0
commit db19eb4
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from "axios"; | ||
import { CommandListReponse } from "../data/response"; | ||
import { API_URL } from "../environment"; | ||
|
||
export const getCommands = async (): Promise<CommandListReponse> => { | ||
try { | ||
const { data } = await axios.get<CommandListReponse>(`${API_URL}/commands/`) | ||
return data; | ||
} catch (error) { | ||
console.error(error) | ||
throw error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CommandResponse } from "../data/response"; | ||
|
||
interface CommandRowProp extends CommandResponse { | ||
handleDelete: () => void; | ||
} | ||
|
||
const CommandRow = ({ id, name, params, format, created_on, updated_on, handleDelete }: CommandRowProp) => { | ||
return ( | ||
<tr> | ||
<th>{id}</th> | ||
<th>{name}</th> | ||
<th>{params}</th> | ||
<th>{format}</th> | ||
<th>{created_on}</th> | ||
<th>{updated_on}</th> | ||
<th><button onClick={handleDelete}>Delete {id}</button></th> | ||
</tr> | ||
) | ||
} | ||
|
||
export default CommandRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useEffect, useState } from "react" | ||
import { CommandResponse } from "../data/response" | ||
import { getCommands } from "./command_api" | ||
import CommandRow from "./row" | ||
|
||
const CommandTable = () => { | ||
const [commands, setCommands] = useState<CommandResponse[]>([]) | ||
|
||
const getCommandsFn = async () => { | ||
const data = await getCommands(); | ||
setCommands(data.data) | ||
} | ||
|
||
useEffect(() => { | ||
getCommandsFn(); | ||
}, []) | ||
|
||
const handleDelete = (id: number) => { | ||
return () => { setCommands(commands.filter((value) => value.id != id)) } | ||
} | ||
|
||
return ( | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>ID: </th> | ||
<th>Name: </th> | ||
<th>Params: </th> | ||
<th>Format: </th> | ||
<th>Created On: </th> | ||
<th>Updated On: </th> | ||
<th>Delete</th> | ||
</tr> | ||
</thead> | ||
<thead> | ||
{commands.map(value => (<CommandRow {...value} handleDelete={handleDelete(value.id)} />))} | ||
</thead> | ||
</table> | ||
) | ||
} | ||
|
||
export default CommandTable; |