-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UILD-427: Authority validation - Creator of Work (#61)
- Loading branch information
1 parent
06ae48f
commit cc8184b
Showing
24 changed files
with
562 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useState, useCallback } from 'react'; | ||
import BaseApi from '@common/api/base.api'; | ||
import { StatusType } from '@common/constants/status.constants'; | ||
import { UserNotificationFactory } from '@common/services/userNotification'; | ||
import { useLoadingState, useStatusState } from '@src/store'; | ||
|
||
interface RequestConfig { | ||
url: string; | ||
method?: APIRequestMethod; | ||
urlParams?: Record<string, string>; | ||
urlParam?: { name: string; value: string | number }; | ||
requestParams?: RequestInit; | ||
body?: unknown; | ||
errorMessageId?: string; | ||
} | ||
|
||
interface ApiResponse<T> { | ||
data: T | null; | ||
} | ||
|
||
export function useApi<T>() { | ||
const { setIsLoading } = useLoadingState(); | ||
const { addStatusMessagesItem } = useStatusState(); | ||
const [state, setState] = useState<ApiResponse<T>>({ | ||
data: null, | ||
}); | ||
|
||
const makeRequest = useCallback( | ||
async ({ url, method = 'GET', urlParams, urlParam, requestParams, body, errorMessageId }: RequestConfig) => { | ||
setIsLoading(true); | ||
|
||
try { | ||
const finalUrl = BaseApi.generateUrl(url, urlParam); | ||
|
||
const response = await BaseApi.getJson({ | ||
url: finalUrl, | ||
urlParams, | ||
requestParams: { | ||
method, | ||
headers: { 'content-type': 'application/json' }, | ||
...requestParams, | ||
...(typeof body === 'object' && body !== null ? { body: JSON.stringify(body, null, 2) } : {}), | ||
}, | ||
}); | ||
|
||
setState({ data: response }); | ||
|
||
return response; | ||
} catch (error) { | ||
addStatusMessagesItem?.( | ||
UserNotificationFactory.createMessage(StatusType.error, errorMessageId ?? 'ld.errorMakingApiRequest'), | ||
); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}, | ||
[], | ||
); | ||
|
||
return { | ||
...state, | ||
makeRequest, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useComplexLookupState } from '@src/store'; | ||
|
||
export const useComplexLookupValidation = () => { | ||
const { | ||
authorityAssignmentCheckFailedIds, | ||
addAuthorityAssignmentCheckFailedIdsItem, | ||
resetAuthorityAssignmentCheckFailedIds, | ||
} = useComplexLookupState(); | ||
|
||
const addFailedEntryId = (id: string) => { | ||
addAuthorityAssignmentCheckFailedIdsItem?.(id); | ||
}; | ||
|
||
const clearFailedEntryIds = () => { | ||
resetAuthorityAssignmentCheckFailedIds(); | ||
}; | ||
|
||
const checkFailedId = (id?: string) => { | ||
if (!id) return false; | ||
|
||
return authorityAssignmentCheckFailedIds.includes(id); | ||
}; | ||
|
||
return { addFailedEntryId, clearFailedEntryIds, checkFailedId }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.