refactor: return types for hooks
This commit is contained in:
@ -3,14 +3,30 @@ import { useStatusesContext } from "@/app/deals/contexts/StatusesContext";
|
||||
import { DealSchema } from "@/lib/client";
|
||||
import { getNewLexorank, sortByLexorank } from "@/utils/lexorank";
|
||||
|
||||
const useGetNewRank = () => {
|
||||
type NewRankGetters = {
|
||||
getNewRankForSameStatus: (
|
||||
statusDeals: DealSchema[],
|
||||
overDealIndex: number,
|
||||
activeDealId: number
|
||||
) => string;
|
||||
getNewRankForAnotherStatus: (
|
||||
statusDeals: DealSchema[],
|
||||
overDealIndex: number
|
||||
) => string;
|
||||
getNewStatusRank: (
|
||||
activeStatusId: number,
|
||||
overStatusId: number
|
||||
) => string | null;
|
||||
};
|
||||
|
||||
const useGetNewRank = (): NewRankGetters => {
|
||||
const { statuses } = useStatusesContext();
|
||||
|
||||
const getNewRankForSameStatus = (
|
||||
statusDeals: DealSchema[],
|
||||
overDealIndex: number,
|
||||
activeDealId: number
|
||||
) => {
|
||||
): string => {
|
||||
const activeDealIndex = statusDeals.findIndex(
|
||||
deal => deal.id === activeDealId
|
||||
);
|
||||
@ -34,7 +50,7 @@ const useGetNewRank = () => {
|
||||
const getNewRankForAnotherStatus = (
|
||||
statusDeals: DealSchema[],
|
||||
overDealIndex: number
|
||||
) => {
|
||||
): string => {
|
||||
const leftLexorank =
|
||||
overDealIndex > 0
|
||||
? LexoRank.parse(statusDeals[overDealIndex - 1].lexorank)
|
||||
@ -46,7 +62,10 @@ const useGetNewRank = () => {
|
||||
return getNewLexorank(leftLexorank, rightLexorank).toString();
|
||||
};
|
||||
|
||||
const getNewStatusRank = (activeStatusId: number, overStatusId: number) => {
|
||||
const getNewStatusRank = (
|
||||
activeStatusId: number,
|
||||
overStatusId: number
|
||||
): string | null => {
|
||||
const sortedStatusList = sortByLexorank(statuses);
|
||||
const overIndex = sortedStatusList.findIndex(
|
||||
s => s.id === overStatusId
|
||||
|
||||
Reference in New Issue
Block a user