@skatteetaten/ds-overlays 2.2.0 → 2.2.1

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.
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { useState, useDeferredValue, useRef, useImperativeHandle, useMemo } from 'react';
2
+ import { useState, useDeferredValue, useRef, useImperativeHandle, useCallback, useMemo } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { Button } from '@skatteetaten/ds-buttons';
5
5
  import { dsI18n, getCommonClassNameDefault, formatNationalIdentityNumber } from '@skatteetaten/ds-core-utils';
@@ -75,16 +75,29 @@ const RolePicker = ({ ref, id, className = getCommonClassNameDefault(), lang, 'd
75
75
  if (noValidBusinesses) {
76
76
  internalTitle = t('rolepicker.NoBusinessesErrorTitle');
77
77
  }
78
+ const handleEntitySelect = useCallback((entity)=>{
79
+ const entityId = 'personId' in entity ? entity.personId : entity.organizationNumber;
80
+ setLoadingEntityId(entityId);
81
+ onEntitySelect?.(entity).then((res)=>{
82
+ setError(res?.error ? {
83
+ entityId,
84
+ message: res.error
85
+ } : undefined);
86
+ setLoadingEntityId(undefined);
87
+ });
88
+ }, [
89
+ onEntitySelect
90
+ ]);
78
91
  const contextValue = useMemo(()=>({
79
- onEntitySelect,
92
+ onEntitySelect: handleEntitySelect,
80
93
  error,
81
94
  setError,
82
95
  loadingEntityId,
83
96
  setLoadingEntityId
84
97
  }), [
85
98
  error,
86
- loadingEntityId,
87
- onEntitySelect
99
+ handleEntitySelect,
100
+ loadingEntityId
88
101
  ]);
89
102
  return /*#__PURE__*/ jsx(RolePickerContext.Provider, {
90
103
  value: contextValue,
@@ -110,18 +123,7 @@ const RolePicker = ({ ref, id, className = getCommonClassNameDefault(), lang, 'd
110
123
  description: `${t('rolepicker.PeopleDescriptionPrefix')} ${formatNationalIdentityNumber(me.personId)}`,
111
124
  svgPath: FavoriteSVGpath,
112
125
  titleAs: 'h2',
113
- onClick: ()=>{
114
- setLoadingEntityId(me.personId);
115
- onEntitySelect?.(me).then((res)=>{
116
- if (res?.error) {
117
- setError({
118
- entityId: me.personId,
119
- message: res.error
120
- });
121
- }
122
- setLoadingEntityId(undefined);
123
- });
124
- }
126
+ onClick: ()=>handleEntitySelect(me)
125
127
  }) : null,
126
128
  getRepresentationText(),
127
129
  displaySearch ? /*#__PURE__*/ jsx(RolePickerFilterInput, {
@@ -33,16 +33,7 @@ const RolePickerBusinessList = ({ businesses, filterQuery, showInactiveBusinesse
33
33
  navRef.current?.querySelectorAll('a')[0].focus();
34
34
  };
35
35
  const handleEntityClicked = async (entity)=>{
36
- ctx?.setLoadingEntityId(entity.organizationNumber);
37
- ctx?.onEntitySelect?.(entity).then((res)=>{
38
- if (res?.error) {
39
- ctx?.setError({
40
- entityId: entity.organizationNumber,
41
- message: res.error
42
- });
43
- }
44
- ctx.setLoadingEntityId(undefined);
45
- });
36
+ ctx?.onEntitySelect?.(entity);
46
37
  };
47
38
  const visibleItems = useMemo(()=>{
48
39
  // lager en dyp kopiering av business-listen for å unngå mutasjon
@@ -30,16 +30,7 @@ const RolePickerPeopleList = ({ people, filterQuery, showDeceasedPeople: showDec
30
30
  navRef.current?.querySelectorAll('a')[0].focus();
31
31
  };
32
32
  const handleEntityClicked = async (entity)=>{
33
- ctx?.setLoadingEntityId(entity.personId);
34
- ctx?.onEntitySelect?.(entity).then((res)=>{
35
- if (res?.error) {
36
- ctx?.setError({
37
- entityId: entity.personId,
38
- message: res.error
39
- });
40
- }
41
- ctx.setLoadingEntityId(undefined);
42
- });
33
+ ctx?.onEntitySelect?.(entity);
43
34
  };
44
35
  const visibleItems = useMemo(()=>{
45
36
  // lager en dyp kopiering av person-listen for å unngå mutasjon
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@skatteetaten/ds-overlays",
3
3
  "groupId": "no.skatteetaten.aurora",
4
- "version": "2.2.0",
4
+ "version": "2.2.1",
5
5
  "main": "./index.esm.js",
6
6
  "type": "module",
7
7
  "module": "./index.esm.js",
@@ -16,16 +16,16 @@
16
16
  "i18next": "^24 || ^25",
17
17
  "react": "^19 ",
18
18
  "react-i18next": "^15",
19
- "@skatteetaten/ds-core-utils": "2.2.0",
20
- "@skatteetaten/ds-buttons": "2.2.0",
21
- "@skatteetaten/ds-forms": "2.2.0",
22
- "@skatteetaten/ds-icons": "2.2.0",
23
- "@skatteetaten/ds-navigation": "2.2.0",
24
- "@skatteetaten/ds-typography": "2.2.0",
25
- "@skatteetaten/ds-progress": "2.2.0",
26
- "@skatteetaten/ds-status": "2.2.0",
19
+ "@skatteetaten/ds-core-utils": "2.2.1",
20
+ "@skatteetaten/ds-buttons": "2.2.1",
21
+ "@skatteetaten/ds-forms": "2.2.1",
22
+ "@skatteetaten/ds-icons": "2.2.1",
23
+ "@skatteetaten/ds-navigation": "2.2.1",
24
+ "@skatteetaten/ds-typography": "2.2.1",
25
+ "@skatteetaten/ds-progress": "2.2.1",
26
+ "@skatteetaten/ds-status": "2.2.1",
27
27
  "date-fns": "^4",
28
- "@skatteetaten/ds-content": "2.2.0",
28
+ "@skatteetaten/ds-content": "2.2.1",
29
29
  "@floating-ui/react": "0.26.28"
30
30
  },
31
31
  "dependencies": {},
@@ -48,7 +48,7 @@ export interface RolePickerProps extends BaseProps, Partial<Pick<ModalProps, 'di
48
48
  children?: ReactNode;
49
49
  }
50
50
  export type RolePickerContextProps = {
51
- onEntitySelect?: OnEntitySelectHandler;
51
+ onEntitySelect?: (entity: Entity) => void;
52
52
  error?: {
53
53
  entityId: string;
54
54
  message: string;