mirror of
https://github.com/thedevs-network/kutt-extension.git
synced 2026-02-03 13:53:23 +00:00
feat: save user information to storage on successful api validation
This commit is contained in:
@@ -95,7 +95,7 @@ function getUserSettings(apikey: string): AxiosPromise<any> {
|
||||
});
|
||||
}
|
||||
|
||||
type DomainEntryProperties = {
|
||||
export type DomainEntryProperties = {
|
||||
address: string;
|
||||
banned: boolean;
|
||||
created_at: string;
|
||||
@@ -104,7 +104,7 @@ type DomainEntryProperties = {
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
type UserSettingsResponseProperties = {
|
||||
export type UserSettingsResponseProperties = {
|
||||
apikey: string;
|
||||
email: string;
|
||||
domains: DomainEntryProperties[];
|
||||
|
||||
@@ -83,11 +83,16 @@ const OptionsForm = withFormik<OptionsFormProperties, FormValuesProperties>({
|
||||
if (!response.error) {
|
||||
// ToDo: show valid api key status
|
||||
console.log('Valid API Key');
|
||||
// ToDo: Store user information
|
||||
console.log(response.data);
|
||||
|
||||
// Store user account information
|
||||
await updateExtensionSettings(response.data);
|
||||
} else {
|
||||
// errored
|
||||
console.log(response.message);
|
||||
|
||||
// ToDo:
|
||||
// Delete `UserSettingsResponseProperties` fields from settings
|
||||
// This will remove user data completely
|
||||
}
|
||||
|
||||
// enable validate button
|
||||
|
||||
@@ -1,12 +1,35 @@
|
||||
import { browser, Storage } from 'webextension-polyfill-ts';
|
||||
|
||||
import { DomainEntryProperties } from '../Background';
|
||||
|
||||
// Core Extensions settings props
|
||||
type ExtensionSettingsProperties = {
|
||||
apikey: string;
|
||||
autocopy: boolean;
|
||||
history: boolean;
|
||||
email?: string;
|
||||
domains?: DomainEntryProperties[];
|
||||
};
|
||||
|
||||
export function openExtOptionsPage(): Promise<void> {
|
||||
return browser.runtime.openOptionsPage();
|
||||
}
|
||||
|
||||
// update extension settings in browser storage
|
||||
export function updateExtensionSettings(settings: Storage.StorageAreaSetItemsType): Promise<void> {
|
||||
export function saveExtensionSettings(settings: Storage.StorageAreaSetItemsType): Promise<void> {
|
||||
return browser.storage.local.set({
|
||||
settings,
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function getExtensionSettings(): Promise<{ [s: string]: any }> {
|
||||
return browser.storage.local.get('settings');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export async function updateExtensionSettings(newFields: { [s: string]: any }): Promise<void> {
|
||||
const { settings = {} } = await getExtensionSettings();
|
||||
|
||||
return saveExtensionSettings({ ...settings, ...newFields });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user