Object data

This commit is contained in:
cracklesparkle
2024-11-26 18:00:18 +09:00
parent a4513e7e7a
commit bd0a317e76
17 changed files with 1517 additions and 719 deletions

View File

@ -0,0 +1,100 @@
import React from 'react'
import useSWR from 'swr'
import { fetcher } from '../../http/axiosInstance'
import { BASE_URL } from '../../constants'
import { Text } from '@mantine/core'
interface ITCBParameterProps {
value: string,
vtable: string,
inactive?: boolean
}
interface vStreet {
id: number,
id_city: number,
name: string,
kv: number
}
interface tType {
id: number,
name: string,
}
const TCBParameter = ({
value,
vtable
}: ITCBParameterProps) => {
//Get value
const { data: tcbValue } = useSWR(
`/general/params/tcb?id=${value}&vtable=${vtable}`,
(url) => fetcher(url, BASE_URL.ems).then(res => res[0]),
{
revalidateOnFocus: false
}
)
//Get available values
const { data: tcbAll } = useSWR(
`/general/params/tcb?vtable=${vtable}`,
(url) => fetcher(url, BASE_URL.ems).then(res => res),
{
revalidateOnFocus: false
}
)
const TCBValue = (vtable: string) => {
switch (vtable) {
case 'vStreets':
return (
<Text>
{JSON.stringify(tcbValue)}
</Text>
)
case 'tTypes':
return (
<Text>
{(tcbValue as tType)?.name}
</Text>
)
case 'vPipesGround':
return (
<Text>
{(tcbValue)?.name}
</Text>
)
case 'vRepairEvent':
return (
<Text>
{(tcbValue)?.name}
</Text>
)
case 'vPipesMaterial':
return (
<Text>
{(tcbValue)?.name}
</Text>
)
case 'vBoilers':
return (
<Text>
{(tcbValue)?.name}
</Text>
)
default:
return (
<Text>
{JSON.stringify(tcbValue)}
</Text>
)
}
}
return (
TCBValue(vtable)
)
}
export default TCBParameter