43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
|
|
import apiService from '@/services/api.service'
|
|||
|
|
import { usePermission } from '@/utils/hooks/usePermission'
|
|||
|
|
import { getActiveCulture, LOCALE_DATE_FORMAT, toTwoLetterCulture } from '@/utils/localeFormat'
|
|||
|
|
import dayjs from 'dayjs'
|
|||
|
|
import { useEffect, useState } from 'react'
|
|||
|
|
|
|||
|
|
export type ProfileRow = Record<string, unknown>
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Persona ekranının ("My" ListForm) satırlarını okur. Satır süzmesi (oturumdaki kullanıcı) ve
|
|||
|
|
* yetki ListForm'da kalır; profil yalnızca gösterir. Yetki yoksa istek atılmaz.
|
|||
|
|
*/
|
|||
|
|
export const useMyRows = (listFormCode: string) => {
|
|||
|
|
const { checkPermission } = usePermission()
|
|||
|
|
const allowed = checkPermission(listFormCode)
|
|||
|
|
const [rows, setRows] = useState<ProfileRow[]>([])
|
|||
|
|
const [loading, setLoading] = useState(allowed)
|
|||
|
|
|
|||
|
|
useEffect(() => {
|
|||
|
|
if (!allowed) return
|
|||
|
|
let active = true
|
|||
|
|
apiService
|
|||
|
|
.fetchData<{ data?: ProfileRow[] }>({
|
|||
|
|
method: 'GET',
|
|||
|
|
url: '/api/app/list-form-select/select',
|
|||
|
|
params: { listFormCode, take: 500 },
|
|||
|
|
})
|
|||
|
|
.then((response) => active && setRows(response.data?.data ?? []))
|
|||
|
|
.catch(() => active && setRows([]))
|
|||
|
|
.finally(() => active && setLoading(false))
|
|||
|
|
return () => {
|
|||
|
|
active = false
|
|||
|
|
}
|
|||
|
|
}, [allowed, listFormCode])
|
|||
|
|
|
|||
|
|
return { allowed, rows, loading }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const formatDay = (value: unknown) =>
|
|||
|
|
value
|
|||
|
|
? dayjs(String(value)).locale(toTwoLetterCulture(getActiveCulture())).format(LOCALE_DATE_FORMAT)
|
|||
|
|
: ''
|