Skip to content

Commit

Permalink
Merge branch 'main' into 951_auditList_resource_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
IanMayo authored Jan 4, 2024
2 parents b118cee + 2b01f54 commit 2ec18fe
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/hooks/useCustomId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export default function useCustomid(): UseCustomId {
const { getValues } = useFormContext()
const [create] = useCreate() as any
const resource = useResourceContext()
const { total = 0 } = useGetList(resource, {
sort: { field: 'id', order: 'DESC' },
pagination: { page: 1, perPage: 1 }
const {data : existingRcordes} = useGetList(resource, {
sort: {field: 'id', order: "DESC"},
pagination: {page: 1, perPage: 1}
})
const createPath = useCreatePath()
const redirect = useRedirect()
Expand All @@ -26,10 +26,9 @@ export default function useCustomid(): UseCustomId {
const values = getValues()

const preFix = ID_FIX?.[resource]
const totalItems: number = total
const recordNumber = totalItems + 1
const highestId = existingRcordes?.[0]?.id || 0;
const id =
typeof preFix !== 'undefined' ? `${preFix}-${recordNumber}` : recordNumber
typeof preFix !== 'undefined' ? `${preFix}-${highestId + 1}` : highestId + 1

const data = { id, ...values }

Expand Down

0 comments on commit 2ec18fe

Please sign in to comment.