Skip to content

Instantly share code, notes, and snippets.

@avoajaugochukwu
Created October 3, 2021 10:56
Show Gist options
  • Save avoajaugochukwu/108bc4bf3ffab311c6e0e0835da47f40 to your computer and use it in GitHub Desktop.
Save avoajaugochukwu/108bc4bf3ffab311c6e0e0835da47f40 to your computer and use it in GitHub Desktop.
export const updateFormFieldNameById = (id, value, formField) => {
/*
Find item in array by id and update the name with given value
*/
let _tempFormField = formField.map(r => {
if (id === r.id) {
return { ...r, name: value }
}
return r
})
return _tempFormField
}
export const updateFormFieldNameByIndex = (id, value, formField) => {
/*
Find item in array by index and update the name with given value
*/
let _tempFormField = formField.map((r, index) => {
if (id === index) {
return { ...r, name: value }
}
return r
})
return _tempFormField
}
export const updateFormFieldDescriptionById = (id, value, formField) => {
/*
Find item in array by id and update the name with given value
*/
let _tempFormField = formField.map(r => {
if (id === r.id) {
return { ...r, description: value }
}
return r
})
return _tempFormField
}
export const updateFormFieldDescriptionByIndex = (id, value, formField) => {
/*
Find item in array by index and update the name with given value
*/
let _tempFormField = formField.map((r, index) => {
if (id === index) {
return { ...r, description: value }
}
return r
})
return _tempFormField
}
export const addDeleteToRecordById = (id, formField) => {
let _tempFormField = formField.map(r => {
if (id === r.id) {
return { ...r, _delete: true }
}
return r
})
return _tempFormField
}
export const addDeleteToRecordByIndex = (id, formField) => {
//
let _tempFormField = formField.map((r, index) => {
if (id === index) {
return { ...r, _delete: true }
}
return r
})
let _removeDeletedWithoutId = _tempFormField.filter(item => !(item.id === "" && item._delete === true))
return _removeDeletedWithoutId
}
export const updateFormFieldLinkById = (id, value, formField) => {
/*
Find item in array by id and update the name with given value
*/
let _tempFormField = formField.map(r => {
if (id === r.id) {
return { ...r, link: value }
}
return r
})
return _tempFormField
}
export const updateFormFieldLinkByIndex = (id, value, formField) => {
/*
Find item in array by index and update the name with given value
*/
let _tempFormField = formField.map((r, index) => {
if (id === index) {
return { ...r, link: value }
}
return r
})
return _tempFormField
}
export const updateFormDeleteFileById = (id, formField) => {
/*
Find item in array by id and update the name with given value
*/
let _tempFormField = formField.map(r => {
if (id === r.id) {
return { ...r, client_name: null, file: null }
}
return r
})
return _tempFormField
}
export const updateFormDeleteFileByIndex = (id, formField) => {
/*
Find item in array by index and update the name with given value
*/
let _tempFormField = formField.map((r, index) => {
if (id === index) {
return { ...r, client_name: null, file: null }
}
return r
})
return _tempFormField
}
export const updateOnFormDocumentUploadSuccessById = (id, res, formField) => {
let _tempFormField = formField.map(r => {
if (id === r.id) {
return { ...r, client_name: res.data.client_name, file: res.data.path }
}
return r
})
return _tempFormField
}
export const updateOnFormDocumentUploadSuccessByIndex = (id, res, formField) => {
let _tempFormField = formField.map((r, index) => {
if (id === index) {
return { ...r, client_name: res.data.client_name, file: res.data.path }
}
return r
})
return _tempFormField
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment