mirror of
https://github.com/faiztyanirh/clqms-shadcn-v1.git
synced 2026-04-22 09:35:34 +07:00
change edit to patch on many pages
This commit is contained in:
parent
6afc0067e2
commit
60bf81d439
@ -14,6 +14,6 @@ export async function createAccount(newAccountForm) {
|
||||
return await create(API.ACCOUNT, newAccountForm)
|
||||
}
|
||||
|
||||
export async function editAccount(editAccountForm) {
|
||||
return await update(API.ACCOUNT, editAccountForm)
|
||||
export async function editAccount(editAccountForm, id) {
|
||||
return await update(API.ACCOUNT, editAccountForm, id)
|
||||
}
|
||||
@ -35,9 +35,10 @@ export const detailSections = [
|
||||
{
|
||||
class: "space-y-3",
|
||||
fields: [
|
||||
{ key: "Country", label: "Country" },
|
||||
{ key: "Province", label: "Province" },
|
||||
{ key: "City", label: "City" },
|
||||
{ key: "CountryLabel", label: "Country" },
|
||||
{ key: "ProvinceLabel", label: "Province" },
|
||||
{ key: "CityLabel", label: "City" },
|
||||
{ key: "ZIP", label: "ZIP" },
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -46,7 +47,6 @@ export const detailSections = [
|
||||
{ key: "Street_1", label: "Street 1" },
|
||||
{ key: "Street_2", label: "Street 2" },
|
||||
{ key: "Street_3", label: "Street 3" },
|
||||
{ key: "ZIP", label: "ZIP" },
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
import { untrack } from "svelte";
|
||||
import { API } from "$lib/config/api";
|
||||
import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte";
|
||||
import { getChangedFields } from "$lib/utils/getChangedFields";
|
||||
|
||||
let props = $props();
|
||||
|
||||
@ -50,7 +51,24 @@
|
||||
});
|
||||
|
||||
async function handleEdit() {
|
||||
const result = await formState.save(masterDetail.mode);
|
||||
const currentPayload = formState.form;
|
||||
const originalPayload = masterDetail.formSnapshot;
|
||||
|
||||
const changedFields = getChangedFields(originalPayload, currentPayload);
|
||||
|
||||
if (Object.keys(changedFields).length === 0) {
|
||||
toast('No changes detected');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
AccountID: formState.form.AccountID,
|
||||
...changedFields
|
||||
};
|
||||
|
||||
console.log('Payload:', payload);
|
||||
|
||||
const result = await formState.save(masterDetail.mode, payload);
|
||||
|
||||
if (result.status === 'success') {
|
||||
console.log('Account updated successfully');
|
||||
@ -58,6 +76,8 @@
|
||||
masterDetail.exitForm(true);
|
||||
} else {
|
||||
console.error('Failed to update account:', result.message);
|
||||
const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update account';
|
||||
toast.error(errorMessages)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ export const detailSections = [
|
||||
class: "grid grid-cols-2 gap-4 items-center",
|
||||
fields: [
|
||||
{ key: "ConClassLabel", label: "Container Class" },
|
||||
{ key: "Color", label: "Color" },
|
||||
{ key: "ColorLabel", label: "Color" },
|
||||
{ key: "AdditiveLabel", label: "Additive" },
|
||||
]
|
||||
},
|
||||
|
||||
@ -13,6 +13,6 @@ export async function createDepartment(newDepartmentForm) {
|
||||
return await create(API.DEPARTMENT, newDepartmentForm)
|
||||
}
|
||||
|
||||
export async function editDepartment(editDepartmentForm) {
|
||||
return await update(API.DEPARTMENT, editDepartmentForm)
|
||||
export async function editDepartment(editDepartmentForm, id) {
|
||||
return await update(API.DEPARTMENT, editDepartmentForm, id)
|
||||
}
|
||||
@ -20,8 +20,8 @@ export const detailSections = [
|
||||
{
|
||||
class: "grid grid-cols-2 gap-4 items-center",
|
||||
fields: [
|
||||
{ key: "SiteID", label: "Site" },
|
||||
{ key: "DisciplineID", label: "Discipline" },
|
||||
{ key: "SiteName", label: "Site" },
|
||||
{ key: "DisciplineName", label: "Discipline" },
|
||||
{ key: "DepartmentCode", label: "Department Code" },
|
||||
{ key: "DepartmentName", label: "Department Name" },
|
||||
]
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
import { untrack } from "svelte";
|
||||
import { API } from "$lib/config/api";
|
||||
import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte";
|
||||
import { getChangedFields } from "$lib/utils/getChangedFields";
|
||||
|
||||
let props = $props();
|
||||
|
||||
@ -38,7 +39,24 @@
|
||||
});
|
||||
|
||||
async function handleEdit() {
|
||||
const result = await formState.save(masterDetail.mode);
|
||||
const currentPayload = formState.form;
|
||||
const originalPayload = masterDetail.formSnapshot;
|
||||
|
||||
const changedFields = getChangedFields(originalPayload, currentPayload);
|
||||
|
||||
if (Object.keys(changedFields).length === 0) {
|
||||
toast('No changes detected');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
DepartmentID: formState.form.DepartmentID,
|
||||
...changedFields
|
||||
};
|
||||
|
||||
console.log('Payload:', payload);
|
||||
|
||||
const result = await formState.save(masterDetail.mode, payload);
|
||||
|
||||
if (result.status === 'success') {
|
||||
console.log('Department updated successfully');
|
||||
@ -46,6 +64,8 @@
|
||||
masterDetail.exitForm(true);
|
||||
} else {
|
||||
console.error('Failed to update department:', result.message);
|
||||
const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update department';
|
||||
toast.error(errorMessages)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,6 +13,6 @@ export async function createDiscipline(newDisciplineForm) {
|
||||
return await create(API.DISCIPLINE, newDisciplineForm)
|
||||
}
|
||||
|
||||
export async function editDiscipline(editDisciplineForm) {
|
||||
return await update(API.DISCIPLINE, editDisciplineForm)
|
||||
export async function editDiscipline(editDisciplineForm, id) {
|
||||
return await update(API.DISCIPLINE, editDisciplineForm, id)
|
||||
}
|
||||
@ -24,6 +24,8 @@ export const detailSections = [
|
||||
{ key: "Parent", label: "Parent" },
|
||||
{ key: "DisciplineCode", label: "Discipline Code" },
|
||||
{ key: "DisciplineName", label: "Discipline Name" },
|
||||
{ key: "SeqSrc", label: "Sequence on Screen" },
|
||||
{ key: "SeqRpt", label: "Sequence on Report" },
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
@ -13,6 +13,8 @@ export const disciplineInitialForm = {
|
||||
Parent: '',
|
||||
DisciplineCode: '',
|
||||
DisciplineName: '',
|
||||
SeqScr: '',
|
||||
SeqRpt: '',
|
||||
};
|
||||
|
||||
export const disciplineDefaultErrors = {
|
||||
@ -66,6 +68,23 @@ export const disciplineFormFields = [
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "row",
|
||||
columns: [
|
||||
{
|
||||
key: "SeqSrc",
|
||||
label: "Sequence on Screen",
|
||||
required: false,
|
||||
type: "number",
|
||||
},
|
||||
{
|
||||
key: "SeqRpt",
|
||||
label: "Sequence on Report",
|
||||
required: false,
|
||||
type: "number",
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
import { untrack } from "svelte";
|
||||
import { API } from "$lib/config/api";
|
||||
import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte";
|
||||
import { getChangedFields } from "$lib/utils/getChangedFields";
|
||||
|
||||
let props = $props();
|
||||
|
||||
@ -38,7 +39,24 @@
|
||||
});
|
||||
|
||||
async function handleEdit() {
|
||||
const result = await formState.save(masterDetail.mode);
|
||||
const currentPayload = formState.form;
|
||||
const originalPayload = masterDetail.formSnapshot;
|
||||
|
||||
const changedFields = getChangedFields(originalPayload, currentPayload);
|
||||
|
||||
if (Object.keys(changedFields).length === 0) {
|
||||
toast('No changes detected');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
DisciplineID: formState.form.DisciplineID,
|
||||
...changedFields
|
||||
};
|
||||
|
||||
console.log('Payload:', payload);
|
||||
|
||||
const result = await formState.save(masterDetail.mode, payload);
|
||||
|
||||
if (result.status === 'success') {
|
||||
console.log('Discipline updated successfully');
|
||||
@ -46,6 +64,8 @@
|
||||
masterDetail.exitForm(true);
|
||||
} else {
|
||||
console.error('Failed to update discipline:', result.message);
|
||||
const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update discipline';
|
||||
toast.error(errorMessages)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ export const detailSections = [
|
||||
{ key: "Parent", label: "Parent" },
|
||||
{ key: "LocCode", label: "Location Code" },
|
||||
{ key: "LocFull", label: "Location Name" },
|
||||
{ key: "LocType", label: "Location Type" },
|
||||
{ key: "LocTypeLabel", label: "Location Type" },
|
||||
{ key: "Description", label: "Description" },
|
||||
]
|
||||
},
|
||||
@ -41,8 +41,8 @@ export const detailSections = [
|
||||
{
|
||||
class: "space-y-3",
|
||||
fields: [
|
||||
{ key: "Province", label: "Province" },
|
||||
{ key: "City", label: "City" },
|
||||
{ key: "ProvinceLabel", label: "Province" },
|
||||
{ key: "CityLabel", label: "City" },
|
||||
{ key: "PostCode", label: "Post Code" },
|
||||
{ key: "Email", label: "Email" },
|
||||
]
|
||||
|
||||
@ -13,6 +13,6 @@ export async function createSite(newSiteForm) {
|
||||
return await create(API.SITE, newSiteForm)
|
||||
}
|
||||
|
||||
export async function editSite(editSiteForm) {
|
||||
return await update(API.SITE, editSiteForm)
|
||||
export async function editSite(editSiteForm, id) {
|
||||
return await update(API.SITE, editSiteForm, id)
|
||||
}
|
||||
@ -27,22 +27,11 @@ export const detailSections = [
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "",
|
||||
class: "grid grid-cols-2 gap-4",
|
||||
groups: [
|
||||
{
|
||||
class: "space-y-3",
|
||||
fields: [
|
||||
{ key: "SiteType", label: "Site Type" },
|
||||
]
|
||||
},
|
||||
{
|
||||
class: "space-y-3",
|
||||
fields: [
|
||||
{ key: "SiteClass", label: "Site Class" },
|
||||
]
|
||||
}
|
||||
]
|
||||
class: "grid grid-cols-2 gap-4 items-center",
|
||||
fields: [
|
||||
{ key: "SiteType", label: "Site Type" },
|
||||
{ key: "SiteClass", label: "Site Class" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
import { untrack } from "svelte";
|
||||
import { API } from "$lib/config/api";
|
||||
import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte";
|
||||
import { getChangedFields } from "$lib/utils/getChangedFields";
|
||||
|
||||
let props = $props();
|
||||
|
||||
@ -38,7 +39,24 @@
|
||||
});
|
||||
|
||||
async function handleEdit() {
|
||||
const result = await formState.save(masterDetail.mode);
|
||||
const currentPayload = formState.form;
|
||||
const originalPayload = masterDetail.formSnapshot;
|
||||
|
||||
const changedFields = getChangedFields(originalPayload, currentPayload);
|
||||
|
||||
if (Object.keys(changedFields).length === 0) {
|
||||
toast('No changes detected');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
SiteID: formState.form.SiteID,
|
||||
...changedFields
|
||||
};
|
||||
|
||||
console.log('Payload:', payload);
|
||||
|
||||
const result = await formState.save(masterDetail.mode, payload);
|
||||
|
||||
if (result.status === 'success') {
|
||||
console.log('Site updated successfully');
|
||||
@ -46,6 +64,8 @@
|
||||
masterDetail.exitForm(true);
|
||||
} else {
|
||||
console.error('Failed to update site:', result.message);
|
||||
const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update site';
|
||||
toast.error(errorMessages)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,6 +13,6 @@ export async function createWorkstation(newWorkstationForm) {
|
||||
return await create(API.WORKSTATION, newWorkstationForm)
|
||||
}
|
||||
|
||||
export async function editWorkstation(editWorkstationForm) {
|
||||
return await update(API.WORKSTATION, editWorkstationForm)
|
||||
export async function editWorkstation(editWorkstationForm, id) {
|
||||
return await update(API.WORKSTATION, editWorkstationForm, id)
|
||||
}
|
||||
@ -20,10 +20,12 @@ export const detailSections = [
|
||||
{
|
||||
class: "grid grid-cols-2 gap-4 items-center",
|
||||
fields: [
|
||||
{ key: "DepartmentID", label: "Department" },
|
||||
{ key: "Type", label: "Type" },
|
||||
{ key: "DepartmentName", label: "Department" },
|
||||
{ key: "TypeLabel", label: "Type" },
|
||||
{ key: "WorkstationCode", label: "Workstation Code" },
|
||||
{ key: "WorkstationName", label: "Workstation Name" },
|
||||
{ key: "LinkToName", label: "Link To" },
|
||||
{ key: "isEnableLabel", label: "Enable" },
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
@ -14,7 +14,7 @@ export const workstationInitialForm = {
|
||||
WorkstationName: '',
|
||||
Type: '',
|
||||
LinkTo: '',
|
||||
Enable: '',
|
||||
isEnable: '1',
|
||||
};
|
||||
|
||||
export const workstationDefaultErrors = {
|
||||
@ -84,11 +84,14 @@ export const workstationFormFields = [
|
||||
labelKey: "WorkstationName",
|
||||
},
|
||||
{
|
||||
key: "Enable",
|
||||
key: "isEnable",
|
||||
label: "Enable",
|
||||
required: false,
|
||||
type: "select",
|
||||
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/enable_disable`,
|
||||
type: "toggle",
|
||||
optionsToggle: [
|
||||
{ value: 0, label: 'Disabled' },
|
||||
{ value: 1, label: 'Enabled' }
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
import { untrack } from "svelte";
|
||||
import { API } from "$lib/config/api";
|
||||
import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte";
|
||||
import { getChangedFields } from "$lib/utils/getChangedFields";
|
||||
|
||||
let props = $props();
|
||||
|
||||
@ -38,7 +39,24 @@
|
||||
});
|
||||
|
||||
async function handleEdit() {
|
||||
const result = await formState.save(masterDetail.mode);
|
||||
const currentPayload = formState.form;
|
||||
const originalPayload = masterDetail.formSnapshot;
|
||||
|
||||
const changedFields = getChangedFields(originalPayload, currentPayload);
|
||||
|
||||
if (Object.keys(changedFields).length === 0) {
|
||||
toast('No changes detected');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
WorkstationID: formState.form.WorkstationID,
|
||||
...changedFields
|
||||
};
|
||||
|
||||
console.log('Payload:', payload);
|
||||
|
||||
const result = await formState.save(masterDetail.mode, payload);
|
||||
|
||||
if (result.status === 'success') {
|
||||
console.log('Workstation updated successfully');
|
||||
@ -46,6 +64,8 @@
|
||||
masterDetail.exitForm(true);
|
||||
} else {
|
||||
console.error('Failed to update workstation:', result.message);
|
||||
const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update workstation';
|
||||
toast.error(errorMessages)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
modeOpt: 'default',
|
||||
saveEndpoint: createDepartment,
|
||||
editEndpoint: editDepartment,
|
||||
idKey: 'DepartmentID',
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
modeOpt: 'default',
|
||||
saveEndpoint: createDiscipline,
|
||||
editEndpoint: editDiscipline,
|
||||
idKey: 'DisciplineID',
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
modeOpt: 'default',
|
||||
saveEndpoint: createSite,
|
||||
editEndpoint: editSite,
|
||||
idKey: 'SiteID',
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
modeOpt: 'default',
|
||||
saveEndpoint: createWorkstation,
|
||||
editEndpoint: editWorkstation,
|
||||
idKey: 'WorkstationID',
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user