-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from newfold-labs/enhance/PRESS7-77-skip-404
Enhance/press7 77 skip 404
- Loading branch information
Showing
9 changed files
with
290 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// WordPress | ||
import apiFetch from '@wordpress/api-fetch'; | ||
|
||
// Newfold | ||
import { Checkbox, Container } from '@newfold/ui-component-library'; | ||
import { NewfoldRuntime } from '@newfold-labs/wp-module-runtime'; | ||
|
||
const Skip404 = ( { methods, constants } ) => { | ||
const [ skip404, setSkip404 ] = methods.useState( | ||
NewfoldRuntime.sdk.performance.skip404 | ||
); | ||
|
||
const getSkip404NoticeTitle = () => { | ||
return constants.text.skip404NoticeTitle; | ||
}; | ||
|
||
const handleSkip404Change = () => { | ||
const value = ! skip404; | ||
apiFetch( { | ||
path: 'newfold-performance/v1/settings', | ||
method: 'POST', | ||
data: { | ||
field: { | ||
id: 'skip404', | ||
value, | ||
}, | ||
}, | ||
} ) | ||
.then( () => { | ||
methods.makeNotice( | ||
'skip404-change-notice', | ||
getSkip404NoticeTitle(), | ||
'', | ||
'success', | ||
5000 | ||
); | ||
} ) | ||
.catch( () => { | ||
methods.makeNotice( | ||
'skip404-change-notice', | ||
constants.text.optionNotSet, | ||
'', | ||
'error', | ||
5000 | ||
); | ||
} ); | ||
|
||
setSkip404( value ); | ||
}; | ||
|
||
return ( | ||
<Container.SettingsField | ||
title={ constants.text.skip404Title } | ||
description={ constants.text.skip404Description } | ||
> | ||
<Checkbox | ||
id="skip-404" | ||
name="skip-404" | ||
onChange={ handleSkip404Change } | ||
value={ skip404 } | ||
checked={ skip404 } | ||
label={ __( | ||
'Skip 404 Handling For Static Files', | ||
'wp-module-performance' | ||
) } | ||
/> | ||
</Container.SettingsField> | ||
); | ||
}; | ||
|
||
export default Skip404; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.