File tree Expand file tree Collapse file tree 4 files changed +42
-15
lines changed
phpmyfaq/admin/assets/src Expand file tree Collapse file tree 4 files changed +42
-15
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Fetch data for configuration
3+ *
4+ * This Source Code Form is subject to the terms of the Mozilla Public License,
5+ * v. 2.0. If a copy of the MPL was not distributed with this file, You can
6+ * obtain one at https://mozilla.org/MPL/2.0/.
7+ *
8+ * @package phpMyFAQ
9+ * @author Thorsten Rinne <[email protected] > 10+ * @copyright 2025 phpMyFAQ Team
11+ * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
12+ * @link https://www.phpmyfaq.de
13+ * @since 2025-01-21
14+ */
15+
16+ import { Response } from '../interfaces' ;
17+
18+ export const saveConfiguration = async ( data : FormData ) : Promise < void > => {
19+ try {
20+ const response = ( await fetch ( 'api/configuration' , {
21+ method : 'POST' ,
22+ body : data ,
23+ } ) ) as unknown as Response ;
24+
25+ if ( response . success ) {
26+ return await response . json ( ) ;
27+ } else {
28+ throw new Error ( 'Network response was not ok.' ) ;
29+ }
30+ } catch ( error ) {
31+ console . error ( 'Error updating configuration: ' , error ) ;
32+ throw error ;
33+ }
34+ } ;
Original file line number Diff line number Diff line change 11export * from './attachment' ;
22export * from './category' ;
3+ export * from './configuration' ;
34export * from './faqs' ;
45export * from './forms' ;
56export * from './glossary' ;
Original file line number Diff line number Diff line change 1515
1616import { Tab } from 'bootstrap' ;
1717import { pushErrorNotification , pushNotification } from '../../../../assets/src/utils' ;
18+ import { saveConfiguration } from '../api' ;
19+ import { Response } from '../interfaces' ;
1820
1921export const handleConfiguration = async ( ) : Promise < void > => {
2022 const configTabList : HTMLElement [ ] = [ ] . slice . call ( document . querySelectorAll ( '#configuration-list a' ) ) ;
2123 const result = document . getElementById ( 'pmf-configuration-result' ) as HTMLElement ;
22- const language = document . getElementById ( 'pmf-language' ) as HTMLInputElement ;
2324 if ( configTabList . length ) {
2425 let tabLoaded = false ;
2526 configTabList . forEach ( ( element ) => {
@@ -80,22 +81,12 @@ export const handleSaveConfiguration = async (): Promise<void> => {
8081 const form = document . getElementById ( 'configuration-list' ) as HTMLFormElement ;
8182 const formData = new FormData ( form ) ;
8283
83- const response = await fetch ( './api/configuration' , {
84- method : 'POST' ,
85- body : formData ,
86- } ) ;
87-
88- if ( ! response . ok ) {
89- console . error ( 'Request failed!' ) ;
90- return ;
91- }
92-
93- const json = await response . json ( ) ;
84+ const response = ( await saveConfiguration ( formData ) ) as unknown as Response ;
9485
95- if ( json . success ) {
96- pushNotification ( json . success ) ;
86+ if ( typeof response . success === 'string' ) {
87+ pushNotification ( response . success ) ;
9788 } else {
98- pushErrorNotification ( json . error ) ;
89+ pushErrorNotification ( response . error as string ) ;
9990 }
10091 } ) ;
10192 }
Original file line number Diff line number Diff line change 11export interface Response {
2+ json ( ) : void | PromiseLike < void > ;
23 success : boolean ;
34 message ?: string ;
45 error ?: string ;
You can’t perform that action at this time.
0 commit comments