Skip to content

Commit

Permalink
fix: update model used
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Young authored and hein-j committed Nov 18, 2022
1 parent b1444cd commit ad0beda
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4471,7 +4471,7 @@ export default function MyFlexUpdateForm(props) {
}
try {
await DataStore.save(
Flex0.copyOf(flex0Record, (updated) => {
Flex0.copyOf(flexRecord, (updated) => {
Object.assign(updated, modelFields);
})
);
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen-ui-react/lib/amplify-ui-renderers/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class FormRenderer extends ReactComponentRenderer<BaseComponentPr
factory.createTryStatement(
factory.createBlock(
[
...buildDataStoreExpression(formActionType, importedModelName),
...buildDataStoreExpression(formActionType, importedModelName, dataTypeName),
// call onSuccess hook if it exists
factory.createIfStatement(
factory.createIdentifier('onSuccess'),
Expand Down
8 changes: 6 additions & 2 deletions packages/codegen-ui-react/lib/forms/form-renderer-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,11 @@ export const buildOnChangeStatement = (
);
};

export const buildDataStoreExpression = (dataStoreActionType: 'update' | 'create', importedModelName: string) => {
export const buildDataStoreExpression = (
dataStoreActionType: 'update' | 'create',
importedModelName: string,
dataTypeName: string,
) => {
if (dataStoreActionType === 'update') {
return [
factory.createExpressionStatement(
Expand All @@ -571,7 +575,7 @@ export const buildDataStoreExpression = (dataStoreActionType: 'update' | 'create
),
undefined,
[
factory.createIdentifier(`${lowerCaseFirst(importedModelName)}Record`),
factory.createIdentifier(`${lowerCaseFirst(dataTypeName)}Record`),
factory.createArrowFunction(
undefined,
undefined,
Expand Down

0 comments on commit ad0beda

Please sign in to comment.