@postxl/generator 0.63.5 → 0.64.0
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.
|
@@ -276,6 +276,10 @@ function generateDeleteFunction({ model, meta, m }) {
|
|
|
276
276
|
const backReferenceDelete = [];
|
|
277
277
|
const backReferenceNames = [];
|
|
278
278
|
for (const { referencingField, referencingModel } of model.references) {
|
|
279
|
+
// NOTE: We only delete back references that are required references.
|
|
280
|
+
if (!referencingField.isRequired) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
279
283
|
const refModelMeta = (0, meta_1.getModelMetadata)({ model: referencingModel });
|
|
280
284
|
const refFieldMeta = (0, meta_1.getFieldMetadata)({ field: referencingField });
|
|
281
285
|
const ids = `${refModelMeta.internalSingularName}${(0, string_1.capitalize)(referencingField.name)}s`;
|
|
@@ -101,7 +101,7 @@ export const ${modals.createComponentName} = ({
|
|
|
101
101
|
<Typed.Formik
|
|
102
102
|
initialValues={{ ...INITIAL_VALUES, ...data }}
|
|
103
103
|
validate={(values) => {
|
|
104
|
-
const errors:
|
|
104
|
+
const errors: { [K in keyof CreateInputData]?: string } = {}
|
|
105
105
|
|
|
106
106
|
${getFormikValidationCases({ model })}
|
|
107
107
|
|
|
@@ -311,7 +311,9 @@ function generateDeleteModalModelComponent({ model, meta }) {
|
|
|
311
311
|
});
|
|
312
312
|
return `
|
|
313
313
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
314
|
-
import {
|
|
314
|
+
import { TRPCClientError } from '@trpc/client'
|
|
315
|
+
|
|
316
|
+
import { Formik } from 'formik'
|
|
315
317
|
import React, { useCallback } from 'react'
|
|
316
318
|
import { toast } from 'react-hot-toast'
|
|
317
319
|
|
|
@@ -346,7 +348,12 @@ export const ${components.modals.deleteComponentName} = ({
|
|
|
346
348
|
{
|
|
347
349
|
loading: "Deleting ${meta.userFriendlyName}...",
|
|
348
350
|
success: "${meta.userFriendlyName} deleted!",
|
|
349
|
-
error:
|
|
351
|
+
error: (err) => {
|
|
352
|
+
if (err instanceof TRPCClientError) {
|
|
353
|
+
return err.message
|
|
354
|
+
}
|
|
355
|
+
return 'Something went wrong...'
|
|
356
|
+
},
|
|
350
357
|
},
|
|
351
358
|
)
|
|
352
359
|
} catch (err) {
|
|
@@ -404,7 +411,6 @@ function getFormImports({ model, meta }) {
|
|
|
404
411
|
import { TRPCClientError } from '@trpc/client'
|
|
405
412
|
import React from 'react'
|
|
406
413
|
import { toast } from 'react-hot-toast'
|
|
407
|
-
import { FormikErrors } from 'formik'
|
|
408
414
|
|
|
409
415
|
import { createTypedForm } from '@components/atoms/Form'
|
|
410
416
|
import { ConfirmButton, ModalWithNavigationContainer, Label, ModalWithActions } from '@components/atoms/Modal'
|