mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat(modal): refactor modal types and integrate security action requirements
This commit is contained in:
@@ -4,25 +4,18 @@
|
||||
import { parseTotpEnabled } from '$lib/utils/totp';
|
||||
import { tick } from 'svelte';
|
||||
import { extractError } from '$lib/utils/misc';
|
||||
import type { ModalItem, ModalMode } from '$lib/types/modal';
|
||||
|
||||
interface Props {
|
||||
show?: boolean;
|
||||
mode?:
|
||||
| 'decrypt'
|
||||
| 'encrypt'
|
||||
| 'confirm'
|
||||
| 'prompt'
|
||||
| 'multiselect'
|
||||
| 'totp'
|
||||
| 'totpSetup'
|
||||
| 'report';
|
||||
mode?: ModalMode;
|
||||
title?: string;
|
||||
message?: string;
|
||||
error?: string;
|
||||
placeholder?: string;
|
||||
inputType?: string;
|
||||
inputMaxLength?: number | null;
|
||||
items?: { label: string; value: unknown }[];
|
||||
items?: ModalItem[];
|
||||
initialValue?: unknown;
|
||||
totpActive?: boolean | null;
|
||||
reportTarget?: 'user' | 'paste' | null;
|
||||
|
||||
@@ -1,39 +1,5 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
type ModalMode =
|
||||
| 'decrypt'
|
||||
| 'encrypt'
|
||||
| 'confirm'
|
||||
| 'prompt'
|
||||
| 'multiselect'
|
||||
| 'totp'
|
||||
| 'totpSetup'
|
||||
| 'report';
|
||||
|
||||
type ModalItem = { label: string; value: unknown };
|
||||
|
||||
type ModalState = {
|
||||
show: boolean;
|
||||
mode: ModalMode;
|
||||
title: string;
|
||||
message: string;
|
||||
error: string;
|
||||
placeholder: string;
|
||||
inputType: string;
|
||||
maxInputLength?: number;
|
||||
items: ModalItem[];
|
||||
initialValue: unknown;
|
||||
totpActive: boolean | null;
|
||||
reportTarget: 'user' | 'paste' | null;
|
||||
reportTargetId: string | number | null;
|
||||
reportSiteKey: string | null;
|
||||
confirmButtonText: string;
|
||||
};
|
||||
|
||||
type ModalOpenOptions = Partial<Omit<ModalState, 'show'>> & {
|
||||
mode: ModalMode;
|
||||
cancelValue?: unknown;
|
||||
};
|
||||
import type { ModalOpenOptions, ModalState } from '$lib/types/modal';
|
||||
|
||||
const initialState: ModalState = {
|
||||
show: false,
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
export type ModalMode =
|
||||
| 'decrypt'
|
||||
| 'encrypt'
|
||||
| 'confirm'
|
||||
| 'prompt'
|
||||
| 'multiselect'
|
||||
| 'totp'
|
||||
| 'totpSetup'
|
||||
| 'report';
|
||||
|
||||
export type ModalItem = { label: string; value: unknown };
|
||||
|
||||
export type ModalState = {
|
||||
show: boolean;
|
||||
mode: ModalMode;
|
||||
title: string;
|
||||
message: string;
|
||||
error: string;
|
||||
placeholder: string;
|
||||
inputType: string;
|
||||
maxInputLength?: number;
|
||||
items: ModalItem[];
|
||||
initialValue: unknown;
|
||||
totpActive: boolean | null;
|
||||
reportTarget: 'user' | 'paste' | null;
|
||||
reportTargetId: string | number | null;
|
||||
reportSiteKey: string | null;
|
||||
confirmButtonText: string;
|
||||
};
|
||||
|
||||
export type ModalOpenOptions = Partial<Omit<ModalState, 'show'>> & {
|
||||
mode: ModalMode;
|
||||
cancelValue?: unknown;
|
||||
};
|
||||
@@ -9,10 +9,3 @@ export function parseTotpEnabled(tokenValue: string | null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function needsAdminTotp(totpEnabled: boolean, currentRoles: number, nextRoles: number) {
|
||||
if (!totpEnabled) return false;
|
||||
const nextHasAdmin = (nextRoles & 4) !== 0;
|
||||
const alreadyAdmin = (currentRoles & 4) !== 0;
|
||||
return nextHasAdmin && !alreadyAdmin;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user