sozsoft-platform/ui/src/views/admin/profile/components/profileData.ts
2026-10-05 17:11:06 +03:00

42 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
: ''