Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'strapi-helper-plugin' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
getData = (props, setUpdatingParams = false) => {
const source = getQueryParameters(props.location.search, 'source');
const _limit =
toInteger(getQueryParameters(props.location.search, '_limit')) ||
this.getCurrentModelDefaultLimit();
const _page =
toInteger(getQueryParameters(props.location.search, '_page')) || 1;
const _sort = this.findPageSort(props); // TODO sort
const _q = getQueryParameters(props.location.search, '_q') || '';
const params = { _limit, _page, _sort, _q };
const filters = generateFiltersFromSearch(props.location.search);
this.props.setParams(params, filters);
this.props.getData(props.match.params.slug, source, setUpdatingParams);
};
removeRelation,
reorderDiffRow,
reorderRow,
resetProps,
setEditFieldToSelect,
setListFieldToEditIndex,
shouldToggleModalSubmit,
}) {
strapi.useInjectReducer({ key: 'settingViewModel', reducer, pluginId });
strapi.useInjectSaga({ key: 'settingViewModel', saga, pluginId });
const [showWarningSubmit, setWarningSubmit] = useState(false);
const [showWarningCancel, setWarningCancel] = useState(false);
const toggleWarningSubmit = () => setWarningSubmit(prevState => !prevState);
const toggleWarningCancel = () => setWarningCancel(prevState => !prevState);
const source = getQueryParameters(search, 'source');
const redirectUrl = getQueryParameters(search, 'redirectUrl');
useEffect(() => {
getData(name, source);
return () => {
resetProps();
};
}, [getData, name, resetProps, source]);
useEffect(() => {
if (showWarningSubmit) {
toggleWarningSubmit();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [shouldToggleModalSubmit]);
const getAttributes = useMemo(() => {
const handleSubmit = async e => {
e.preventDefault();
const schema = forms[authType].schema;
let formErrors = {};
try {
await schema.validate(modifiedData, { abortEarly: false });
try {
if (modifiedData.news === true) {
await request('https://analytics.strapi.io/register', {
method: 'POST',
body: omit(modifiedData, ['password', 'confirmPassword']),
signal,
});
}
} catch (err) {
// Do nothing
}
try {
const requestEndPoint = forms[authType].endPoint;
const requestURL = `/admin/auth/${requestEndPoint}`;
const body = omit(modifiedData, 'news');
if (authType === 'forgot-password') {
set(body, 'url', `${strapi.remoteURL}/auth/reset-password`);
});
}
} catch (err) {
// Do nothing
}
try {
const requestEndPoint = forms[authType].endPoint;
const requestURL = `/admin/auth/${requestEndPoint}`;
const body = omit(modifiedData, 'news');
if (authType === 'forgot-password') {
set(body, 'url', `${strapi.remoteURL}/auth/reset-password`);
}
const { jwt, user, ok } = await request(requestURL, {
method: 'POST',
body,
signal,
});
if (authType === 'forgot-password' && ok === true) {
dispatch({
type: 'SUBMIT_SUCCESS',
email: modifiedData.email,
});
} else {
auth.setToken(jwt, modifiedData.rememberMe);
auth.setUserInfo(user, modifiedData.rememberMe);
}
} catch (err) {
const formattedError = formatErrorFromRequest(err);
.updateIn(['modifiedSchema', 'models', ...action.keys.split('.'), 'fields'], list => {
// Don't do any check if removing the last item of the array
if (action.index === list.size - 1) {
return list.delete(action.index);
}
const path = action.keys.split('.');
const modelName = path.length > 2 ? path[2] : path[0];
const layout = state.getIn(['modifiedSchema', 'layout', modelName, 'attributes']);
const manager = new Manager(state, list, action.keys, action.index, layout);
const attrToRemoveInfos = manager.attrToRemoveInfos; // Retrieve the removed item infos
const arrayOfLastLineElements = manager.arrayOfEndLineElements;
const isRemovingAFullWidthNode = attrToRemoveInfos.bootstrapCol === 12;
let newList;
if (isRemovingAFullWidthNode) { // If removing we need to add the corresponding missing col in the prev line
const currentNodeLine = findIndex(arrayOfLastLineElements, ['index', attrToRemoveInfos.index]); // Used only to know if removing a full size element on the first line
if (currentNodeLine === 0) {
newList = list
.delete(action.index);
} else {
const previousNodeLine = currentNodeLine - 1;
const firstElementOnLine = previousNodeLine === 0 ? 0 : arrayOfLastLineElements[previousNodeLine - 1].index + 1;
const lastElementOnLine = arrayOfLastLineElements[previousNodeLine].index + 1;
const previousLineRangeIndexes = firstElementOnLine === lastElementOnLine ? [firstElementOnLine] : range(firstElementOnLine, lastElementOnLine);
.updateIn(['modifiedSchema', 'models', ...action.keys.split('.'), 'fields'], list => {
const draggedItemName = state.get('draggedItemName');
const draggedItemIndex = list.indexOf(draggedItemName);
const path = action.keys.split('.');
const modelName = path.length > 2 ? path[2] : path[0];
const layout = state.getIn(['modifiedSchema', 'layout', modelName, 'attributes']);
const manager = new Manager(state, list, action.keys, draggedItemIndex, layout);
const arrayOfLastLineElements = manager.arrayOfEndLineElements;
const itemInfos = manager.getAttrInfos(draggedItemIndex);
const isFullSize = itemInfos.bootstrapCol === 12;
const dropLineBounds = { left: manager.getBound(false, action.hoverIndex), right: manager.getBound(true, action.hoverIndex) };
const hasMoved = state.get('hasMoved'); // Used only for non full-width elements
if (isFullSize && draggedItemIndex !== -1) {
const upwards = action.dragIndex > action.hoverIndex;
const indexToDrop = upwards ? get(dropLineBounds, 'left.index', 0) : get(dropLineBounds, 'right.index', list.size -1);
updateHoverIndex = false;
shouldUpdateListOnDrop = false;
return list
.delete(draggedItemIndex)
.insert(indexToDrop, draggedItemName);
}
// Search to open modal add fields for the main type (content type)
push({ search: '' });
}
} else {
console.error('This case is not handled');
}
return;
}
dispatch({
type: 'RESET_PROPS',
});
} catch (err) {
console.log({ err });
const errors = getYupInnerErrors(err);
dispatch({
type: 'SET_ERRORS',
errors,
});
}
};
const handleToggle = () => {
files.forEach(file => {
formData.append(`files.${key}`, file);
});
});
// Change the request helper default headers so we can pass a FormData
const headers = {};
const method = isCreatingEntry ? 'POST' : 'PUT';
const endPoint = isCreatingEntry ? slug : `${slug}/${id}`;
emitEvent(isCreatingEntry ? 'willCreateEntry' : 'willEditEntry');
try {
// Time to actually send the data
await request(
getRequestUrl(endPoint),
{
method,
headers,
body: formData,
signal,
},
false,
false
);
emitEvent(isCreatingEntry ? 'didCreateEntry' : 'didEditEntry');
dispatch({
type: 'SUBMIT_SUCCESS',
});
redirectToPreviousPage();
} catch (err) {
Object.keys(filesToUpload).forEach(key => {
const files = filesToUpload[key];
files.forEach(file => {
formData.append(`files.${key}`, file);
});
});
// Change the request helper default headers so we can pass a FormData
const headers = {};
const method = isCreatingEntry ? 'POST' : 'PUT';
const endPoint = isCreatingEntry ? slug : `${slug}/${id}`;
try {
// Time to actually send the data
await request(
getRequestUrl(endPoint),
{
method,
headers,
params: { source },
body: formData,
signal,
},
false,
false
);
emitEvent('didSaveEntry');
redirectToPreviousPage();
} catch (err) {
const error = get(
err,
function ListView() {
const { formatMessage } = useGlobalContext();
// Fake data for now
const data = [
{
id: 0,
name: 'gatsby',
isEnabled: false,
url: 'http://thisisanexample.com/1234867874',
headers: {
Authorisation: 'x-secret',
},
hooks: ['createEntry', 'editEntry', 'deleteEntry', 'createMedia'],
links: [
{
icon: 'pencil',
onClick: () => {