@stoker-platform/web-app 0.5.58 → 0.5.59

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.59
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: improve permissions change logic
8
+ - Updated dependencies
9
+ - @stoker-platform/web-client@0.5.36
10
+
3
11
  ## 0.5.58
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.58",
3
+ "version": "0.5.59",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
@@ -53,7 +53,7 @@
53
53
  "@sentry/react": "^10.47.0",
54
54
  "@stoker-platform/node-client": "0.5.38",
55
55
  "@stoker-platform/utils": "0.5.32",
56
- "@stoker-platform/web-client": "0.5.35",
56
+ "@stoker-platform/web-client": "0.5.36",
57
57
  "@tanstack/react-table": "^8.21.3",
58
58
  "@types/react": "18.3.13",
59
59
  "@types/react-dom": "18.3.1",
@@ -14,6 +14,7 @@ import {
14
14
  RelationField,
15
15
  RelationList,
16
16
  StokerCollection,
17
+ StokerPermissions,
17
18
  StokerRecord,
18
19
  StokerRole,
19
20
  } from "@stoker-platform/types"
@@ -30,6 +31,7 @@ import {
30
31
  GetSomeOptions,
31
32
  getTimezone,
32
33
  keepTimezone,
34
+ onStokerPermissionsChange,
33
35
  onStokerSignOut,
34
36
  subscribeMany,
35
37
  SubscribeManyOptions,
@@ -153,7 +155,7 @@ function Collection({
153
155
  const schema = getSchema()
154
156
  const customization = getCollectionConfigModule(labels.collection)
155
157
  const timezone = getTimezone()
156
- const permissions = getCurrentUserPermissions()
158
+ const [permissions, setPermissions] = useState<StokerPermissions | null>(() => getCurrentUserPermissions())
157
159
  if (!permissions?.Role) throw new Error("PERMISSION_DENIED")
158
160
  const { toast } = useToast()
159
161
 
@@ -236,6 +238,13 @@ function Collection({
236
238
 
237
239
  const preventChange = isRouteLoadingImmediate.has(location.pathname)
238
240
 
241
+ useEffect(() => {
242
+ const unsubscribe = onStokerPermissionsChange(() => {
243
+ setPermissions(getCurrentUserPermissions())
244
+ })
245
+ return unsubscribe
246
+ }, [])
247
+
239
248
  const onTabChange = useCallback((value: string) => {
240
249
  Object.values(unsubscribe.current).forEach((unsubscribe) => unsubscribe.forEach((unsubscribe) => unsubscribe()))
241
250
  unsubscribe.current = {}
@@ -1333,7 +1342,7 @@ function Collection({
1333
1342
  }, [calendarConfig, schema])
1334
1343
 
1335
1344
  const canAddRecords =
1336
- permissions.collections?.[labels.collection].operations.includes("Create") &&
1345
+ permissions.collections?.[labels.collection]?.operations.includes("Create") &&
1337
1346
  !hasEntityRestrictions.some((entityRestriction) => entityRestriction.type === "Individual") &&
1338
1347
  !disableCreate
1339
1348
  const isCreateDisabled = getConnectionStatus() === "Offline" && (isOfflineDisabled || serverWriteOnly)
@@ -1641,6 +1650,8 @@ function Collection({
1641
1650
  [recordTitle],
1642
1651
  )
1643
1652
 
1653
+ if (!permissions.collections?.[labels.collection]) return null
1654
+
1644
1655
  return (
1645
1656
  !collection.singleton && (
1646
1657
  <>