@stoker-platform/web-app 0.5.245 → 0.5.247

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,17 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.247
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: show validation errors on create record form
8
+
9
+ ## 0.5.246
10
+
11
+ ### Patch Changes
12
+
13
+ - fix: use record clone when updating multiple records
14
+
3
15
  ## 0.5.245
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.245",
3
+ "version": "0.5.247",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
package/src/Form.tsx CHANGED
@@ -3825,6 +3825,7 @@ function RecordForm({
3825
3825
  }, [])
3826
3826
 
3827
3827
  const suppressDraftSaveRef = useRef(false)
3828
+ const onValidFiredRef = useRef(false)
3828
3829
 
3829
3830
  const previous = useRef<StokerRecord | undefined>(undefined)
3830
3831
 
@@ -4262,6 +4263,7 @@ function RecordForm({
4262
4263
  if (operation === "create") {
4263
4264
  const serverWrite = isServerCreate(collection, userData)
4264
4265
  const docId = doc(dbCollection(db, "tenants", tenantId, labels.collection)).id
4266
+ onValidFiredRef.current = false
4265
4267
 
4266
4268
  setGlobalLoading("+", docId, serverWrite, !(serverWrite || isServerReadOnly))
4267
4269
  if (serverWrite || isServerReadOnly) {
@@ -4270,6 +4272,14 @@ function RecordForm({
4270
4272
 
4271
4273
  const onValid = () => {
4272
4274
  if (!(serverWrite || isServerReadOnly)) {
4275
+ onValidFiredRef.current = true
4276
+ toast({
4277
+ // eslint-disable-next-line security/detect-object-injection
4278
+ description: `${recordTitle} ${values[recordTitleField] ? values[recordTitleField] : ""} created.`,
4279
+ })
4280
+ suppressDraftSaveRef.current = true
4281
+ localStorage.removeItem(`stoker-draft-${labels.collection}`)
4282
+ localStorage.removeItem(`stoker-draft-owner-${labels.collection}`)
4273
4283
  if (onSuccess) onSuccess({ ...recordToSave, id: docId, Collection_Path: path } as StokerRecord)
4274
4284
  }
4275
4285
  }
@@ -4329,22 +4339,15 @@ function RecordForm({
4329
4339
  })
4330
4340
  .catch((error) => {
4331
4341
  console.error(error)
4332
- if (isServerReadOnly || serverWrite) {
4333
- setError(error.message.replace("VALIDATION_ERROR: ", ""))
4342
+ const message = error.message.replace("VALIDATION_ERROR: ", "")
4343
+ if (!onValidFiredRef.current) {
4344
+ setError(message)
4334
4345
  } else {
4335
- if (error.message.includes("VALIDATION_ERROR")) {
4336
- toast({
4337
- description: error.message.replace("VALIDATION_ERROR: ", ""),
4338
- variant: "destructive",
4339
- duration: 10000000,
4340
- })
4341
- } else {
4342
- toast({
4343
- // eslint-disable-next-line security/detect-object-injection
4344
- description: `${recordTitle} ${values[recordTitleField] ? values[recordTitleField] : ""} failed to create.`,
4345
- variant: "destructive",
4346
- })
4347
- }
4346
+ toast({
4347
+ description: message,
4348
+ variant: "destructive",
4349
+ ...(error.message.includes("VALIDATION_ERROR") ? { duration: 10000000 } : {}),
4350
+ })
4348
4351
  }
4349
4352
  })
4350
4353
  .finally(() => {
@@ -4353,15 +4356,6 @@ function RecordForm({
4353
4356
  }
4354
4357
  setGlobalLoading("-", docId, undefined, !(serverWrite || isServerReadOnly))
4355
4358
  })
4356
- if (!(serverWrite || isServerReadOnly)) {
4357
- toast({
4358
- // eslint-disable-next-line security/detect-object-injection
4359
- description: `${recordTitle} ${values[recordTitleField] ? values[recordTitleField] : ""} created.`,
4360
- })
4361
- suppressDraftSaveRef.current = true
4362
- localStorage.removeItem(`stoker-draft-${labels.collection}`)
4363
- localStorage.removeItem(`stoker-draft-owner-${labels.collection}`)
4364
- }
4365
4359
  } else if (operation === "update") {
4366
4360
  if (!id) {
4367
4361
  setError("No ID provided for update operation")
@@ -4465,7 +4459,7 @@ function RecordForm({
4465
4459
  const serverWrite = isServerUpdate(collection, recordToSave, undefined, selectedRecord)
4466
4460
  setGlobalLoading("+", selectedRecord.id, serverWrite, !(serverWrite || isServerReadOnly))
4467
4461
 
4468
- return updateRecord(path, selectedRecord.id, recordToSave, {
4462
+ return updateRecord(path, selectedRecord.id, cloneDeep(recordToSave), {
4469
4463
  originalRecord: selectedRecord,
4470
4464
  })
4471
4465
  .catch((error) => {