form-craft-package 1.11.1-dev.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/api/client.ts
CHANGED
|
@@ -198,18 +198,23 @@ export const auth = async (
|
|
|
198
198
|
let userRoleIds: string[] = []
|
|
199
199
|
const userForm = forms.find((form) => form.isUser)
|
|
200
200
|
if (userForm?.id && loginAuthRes.data.id) {
|
|
201
|
+
let userRolesRes: AxiosResponse<any> | undefined
|
|
201
202
|
try {
|
|
202
|
-
|
|
203
|
+
userRolesRes = await apiClient.post(`/api/report/data/${userForm.id}`, {
|
|
203
204
|
joins: [],
|
|
204
205
|
match: JSON.stringify({ DeletedDate: null, 'Data.loginUser_id': loginAuthRes.data.id }),
|
|
205
206
|
project: JSON.stringify({ Data_roles: '$Data.loginUser_roles' }),
|
|
206
207
|
skip: 0,
|
|
207
208
|
limit: 1,
|
|
208
209
|
})
|
|
209
|
-
const fetchedRoles = userRolesRes?.data?.data?.[0]?.Data_roles
|
|
210
|
-
if (Array.isArray(fetchedRoles))
|
|
211
|
-
userRoleIds = fetchedRoles.filter((role): role is string => typeof role === 'string' && role.length > 0)
|
|
212
210
|
} catch {}
|
|
211
|
+
if (userRolesRes?.data?.totalRecords === 0 && !JSON.parse(loginAuthRes.data.roles).includes('Admin')) {
|
|
212
|
+
cookieHandler.empty()
|
|
213
|
+
throw { status: 400, response: { status: 400, data: 'User is not found!' } }
|
|
214
|
+
}
|
|
215
|
+
const fetchedRoles = userRolesRes?.data?.data?.[0]?.Data_roles
|
|
216
|
+
if (Array.isArray(fetchedRoles))
|
|
217
|
+
userRoleIds = fetchedRoles.filter((role): role is string => typeof role === 'string' && role.length > 0)
|
|
213
218
|
}
|
|
214
219
|
|
|
215
220
|
if (userRoleIds.length)
|
|
@@ -16,12 +16,6 @@ import WarningIcon from '../../../../common/warning-icon'
|
|
|
16
16
|
import FormDataLoadingIndicatorModal from '../../../../modals/form-data-loading.modal'
|
|
17
17
|
import { IFormContext } from '../../1-row'
|
|
18
18
|
import { useButtonNavigateAction } from './use-button-navigate.hook'
|
|
19
|
-
import {
|
|
20
|
-
buildRolePermissionActionErrorTranslationKey,
|
|
21
|
-
constructDynamicFormHref,
|
|
22
|
-
isNewFormDataPage,
|
|
23
|
-
resolveConditionalText,
|
|
24
|
-
} from '../../../../../functions'
|
|
25
19
|
import { useCustomFunctionCallAction } from './use-custom-function-call.hook'
|
|
26
20
|
import { ELEMENTS_DEFAULT_CLASS } from '../../../../../constants'
|
|
27
21
|
import { useTranslation } from '../../../../common/custom-hooks/use-translation.hook/hook'
|
|
@@ -29,6 +23,7 @@ import { useSendNotificationAction } from './use-send-notification.hook'
|
|
|
29
23
|
import { useSaveUserAccountAction } from './use-save-user-account-action.hook'
|
|
30
24
|
import { useButtonActionPermissions, PermissionBlockKey } from './use-button-action-permissions.hook'
|
|
31
25
|
import useGetCurrentBreakpoint from '../../../../common/custom-hooks/use-window-width.hook'
|
|
26
|
+
import { useConfigContext } from '../../../../companies/context'
|
|
32
27
|
import {
|
|
33
28
|
IButtonElementProps,
|
|
34
29
|
IButtonProps_CustomFunctionCall,
|
|
@@ -47,13 +42,19 @@ import {
|
|
|
47
42
|
TranslationTextSubTypeEnum,
|
|
48
43
|
TranslationTextTypeEnum,
|
|
49
44
|
} from '../../../../../enums'
|
|
50
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
buildRolePermissionActionErrorTranslationKey,
|
|
47
|
+
constructDynamicFormHref,
|
|
48
|
+
isNewFormDataPage,
|
|
49
|
+
resolveConditionalText,
|
|
50
|
+
} from '../../../../../functions'
|
|
51
51
|
|
|
52
52
|
const DuplicateWarningModal = lazy(() => import('../../../../common/duplicate-entry-checker/duplicate-warning.modal'))
|
|
53
53
|
|
|
54
54
|
export const DynamicFormButtonRender = memo((props: IDynamicButton) => {
|
|
55
55
|
const { displayStateProps = {}, formContext = {}, onCustomFunctionCall = () => {} } = props
|
|
56
|
-
const { btnProps, btnKey, textConditions, textConditionsBySubType } =
|
|
56
|
+
const { btnProps, btnKey, textConditions, textConditionsBySubType } =
|
|
57
|
+
displayStateProps as IDynamicButton_DisplayStateProps
|
|
57
58
|
const duplicateCheckModal = useLazyModalOpener()
|
|
58
59
|
|
|
59
60
|
const { getFormById } = useFindDynamiForm()
|
|
@@ -77,7 +78,7 @@ export const DynamicFormButtonRender = memo((props: IDynamicButton) => {
|
|
|
77
78
|
const { config } = useConfigContext()
|
|
78
79
|
const translations = config?.translations
|
|
79
80
|
const getTranslation = useMemo(
|
|
80
|
-
() => (key: string) => (selectedLanguage ? translations?.[key]?.[selectedLanguage as CountryEnum] ?? '' : ''),
|
|
81
|
+
() => (key: string) => (selectedLanguage ? (translations?.[key]?.[selectedLanguage as CountryEnum] ?? '') : ''),
|
|
81
82
|
[selectedLanguage, translations],
|
|
82
83
|
)
|
|
83
84
|
const isElementHidden = useIsNodeHidden(btnKey)
|
|
@@ -455,11 +456,6 @@ export const DynamicFormButtonRender = memo((props: IDynamicButton) => {
|
|
|
455
456
|
const handleButtonClick = useCallback(async () => {
|
|
456
457
|
isPrimaryActionMsgRef.current = true
|
|
457
458
|
|
|
458
|
-
if (isPermissionBlocked) {
|
|
459
|
-
setLoading(false)
|
|
460
|
-
return
|
|
461
|
-
}
|
|
462
|
-
|
|
463
459
|
const handlers: Record<ButtonActionCategoryEnum, () => Promise<void>> = {
|
|
464
460
|
[ButtonActionCategoryEnum.Navigate]: async () => {
|
|
465
461
|
onButtonNavigate(btnProps.primaryAction as IButtonProps_Navigate, btnProps.formId)
|
|
@@ -550,7 +546,6 @@ export const DynamicFormButtonRender = memo((props: IDynamicButton) => {
|
|
|
550
546
|
formDataId,
|
|
551
547
|
isPublic,
|
|
552
548
|
isDuplicateDataFound,
|
|
553
|
-
isPermissionBlocked,
|
|
554
549
|
onFunctionCall,
|
|
555
550
|
onDuplicateData,
|
|
556
551
|
onDeleteData,
|
|
@@ -575,11 +570,11 @@ export const DynamicFormButtonRender = memo((props: IDynamicButton) => {
|
|
|
575
570
|
<Button_FillerPortal
|
|
576
571
|
{...getButtonRenderProps(btnProps)}
|
|
577
572
|
loading={loading || duplicateCheckModal.isPendingTransition || isDuplicateCheckPending}
|
|
578
|
-
disabled={isElementDisabled || isPermissionBlocked}
|
|
573
|
+
disabled={isElementDisabled || (!isPublic && isPermissionBlocked)}
|
|
579
574
|
className={`${ELEMENTS_DEFAULT_CLASS.Button} w-full ${isElementHidden ? 'hidden' : ''}`}
|
|
580
575
|
title={permissionTooltip ? permissionTooltip : ''}
|
|
581
576
|
onClick={(e) => {
|
|
582
|
-
if (isPermissionBlocked) return
|
|
577
|
+
if (!isPublic && isPermissionBlocked) return
|
|
583
578
|
if (
|
|
584
579
|
btnProps.primaryAction.category === ButtonActionCategoryEnum.SaveDataChanges &&
|
|
585
580
|
(isDuplicateDataFound || isDuplicateCheckPending)
|
package/src/enums/index.ts
CHANGED