refactor(secret-input): remove isDirty check
This commit is contained in:
parent
e39552ee68
commit
47b3c80317
9 changed files with 15 additions and 68 deletions
|
|
@ -14,11 +14,9 @@ export const isStoredSecretValue = (value?: string): boolean => {
|
||||||
return value.startsWith("env://") || value.startsWith("file://") || value.startsWith("encv1:");
|
return value.startsWith("env://") || value.startsWith("file://") || value.startsWith("encv1:");
|
||||||
};
|
};
|
||||||
|
|
||||||
type SecretInputProps = Omit<React.ComponentProps<typeof Input>, "type"> & {
|
type SecretInputProps = Omit<React.ComponentProps<typeof Input>, "type">
|
||||||
isDirty?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const SecretInput = ({ className, isDirty, value, ...props }: SecretInputProps) => {
|
export const SecretInput = ({ className, value, ...props }: SecretInputProps) => {
|
||||||
const [revealed, setRevealed] = useState(false);
|
const [revealed, setRevealed] = useState(false);
|
||||||
|
|
||||||
const showAsPlaintext = useMemo(() => {
|
const showAsPlaintext = useMemo(() => {
|
||||||
|
|
@ -26,8 +24,8 @@ export const SecretInput = ({ className, isDirty, value, ...props }: SecretInput
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isStoredSecretValue(value) && !isDirty;
|
return isStoredSecretValue(value);
|
||||||
}, [isDirty, value]);
|
}, [value]);
|
||||||
|
|
||||||
const type = useMemo(() => {
|
const type = useMemo(() => {
|
||||||
if (showAsPlaintext) {
|
if (showAsPlaintext) {
|
||||||
|
|
|
||||||
|
|
@ -214,11 +214,7 @@ export const CreateNotificationForm = ({ onSubmit, mode = "create", initialValue
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Password (Optional)</FormLabel>
|
<FormLabel>Password (Optional)</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput {...field} placeholder="••••••••" />
|
||||||
{...field}
|
|
||||||
isDirty={form.getFieldState("password", form.formState).isDirty}
|
|
||||||
placeholder="••••••••"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
@ -420,11 +416,7 @@ export const CreateNotificationForm = ({ onSubmit, mode = "create", initialValue
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>App Token</FormLabel>
|
<FormLabel>App Token</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput {...field} placeholder="••••••••" />
|
||||||
{...field}
|
|
||||||
isDirty={form.getFieldState("token", form.formState).isDirty}
|
|
||||||
placeholder="••••••••"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Application token from Gotify.</FormDescription>
|
<FormDescription>Application token from Gotify.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
@ -519,11 +511,7 @@ export const CreateNotificationForm = ({ onSubmit, mode = "create", initialValue
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Password (Optional)</FormLabel>
|
<FormLabel>Password (Optional)</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput {...field} placeholder="••••••••" />
|
||||||
{...field}
|
|
||||||
isDirty={form.getFieldState("password", form.formState).isDirty}
|
|
||||||
placeholder="••••••••"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Password for server authentication, if required.</FormDescription>
|
<FormDescription>Password for server authentication, if required.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
@ -580,11 +568,7 @@ export const CreateNotificationForm = ({ onSubmit, mode = "create", initialValue
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>API Token</FormLabel>
|
<FormLabel>API Token</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput {...field} placeholder="••••••••" />
|
||||||
{...field}
|
|
||||||
isDirty={form.getFieldState("apiToken", form.formState).isDirty}
|
|
||||||
placeholder="••••••••"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Application API token from your Pushover application.</FormDescription>
|
<FormDescription>Application API token from your Pushover application.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
@ -644,11 +628,7 @@ export const CreateNotificationForm = ({ onSubmit, mode = "create", initialValue
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Bot Token</FormLabel>
|
<FormLabel>Bot Token</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput {...field} placeholder="123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" />
|
||||||
{...field}
|
|
||||||
isDirty={form.getFieldState("botToken", form.formState).isDirty}
|
|
||||||
placeholder="123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
Telegram bot token. Get this from BotFather when you create your bot.
|
Telegram bot token. Get this from BotFather when you create your bot.
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,6 @@ export const CreateRepositoryForm = ({
|
||||||
placeholder="Enter repository password"
|
placeholder="Enter repository password"
|
||||||
value={field.value ?? ""}
|
value={field.value ?? ""}
|
||||||
onChange={field.onChange}
|
onChange={field.onChange}
|
||||||
isDirty={form.getFieldState("customPassword", form.formState).isDirty}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
|
|
|
||||||
|
|
@ -53,12 +53,7 @@ export const AzureRepositoryForm = ({ form }: Props) => {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Account Key</FormLabel>
|
<FormLabel>Account Key</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput placeholder="••••••••" value={field.value ?? ""} onChange={field.onChange} />
|
||||||
placeholder="••••••••"
|
|
||||||
value={field.value ?? ""}
|
|
||||||
onChange={field.onChange}
|
|
||||||
isDirty={form.getFieldState("accountKey", form.formState).isDirty}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Azure Storage account key for authentication.</FormDescription>
|
<FormDescription>Azure Storage account key for authentication.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
|
||||||
|
|
@ -69,12 +69,7 @@ export const R2RepositoryForm = ({ form }: Props) => {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Secret Access Key</FormLabel>
|
<FormLabel>Secret Access Key</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput placeholder="••••••••" value={field.value ?? ""} onChange={field.onChange} />
|
||||||
placeholder="••••••••"
|
|
||||||
value={field.value ?? ""}
|
|
||||||
onChange={field.onChange}
|
|
||||||
isDirty={form.getFieldState("secretAccessKey", form.formState).isDirty}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>R2 API token Secret Access Key (shown once when creating token).</FormDescription>
|
<FormDescription>R2 API token Secret Access Key (shown once when creating token).</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,7 @@ export const RestRepositoryForm = ({ form }: Props) => {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Password (Optional)</FormLabel>
|
<FormLabel>Password (Optional)</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput placeholder="••••••••" value={field.value ?? ""} onChange={field.onChange} />
|
||||||
placeholder="••••••••"
|
|
||||||
value={field.value ?? ""}
|
|
||||||
onChange={field.onChange}
|
|
||||||
isDirty={form.getFieldState("password", form.formState).isDirty}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Password for REST server authentication.</FormDescription>
|
<FormDescription>Password for REST server authentication.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,7 @@ export const S3RepositoryForm = ({ form }: Props) => {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Secret Access Key</FormLabel>
|
<FormLabel>Secret Access Key</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput placeholder="••••••••" value={field.value ?? ""} onChange={field.onChange} />
|
||||||
placeholder="••••••••"
|
|
||||||
value={field.value ?? ""}
|
|
||||||
onChange={field.onChange}
|
|
||||||
isDirty={form.getFieldState("secretAccessKey", form.formState).isDirty}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>S3 secret access key for authentication.</FormDescription>
|
<FormDescription>S3 secret access key for authentication.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,7 @@ export const SMBForm = ({ form }: Props) => {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Password</FormLabel>
|
<FormLabel>Password</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput placeholder="••••••••" value={field.value ?? ""} onChange={field.onChange} />
|
||||||
placeholder="••••••••"
|
|
||||||
value={field.value ?? ""}
|
|
||||||
onChange={field.onChange}
|
|
||||||
isDirty={form.getFieldState("password", form.formState).isDirty}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Password for SMB authentication.</FormDescription>
|
<FormDescription>Password for SMB authentication.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,7 @@ export const WebDAVForm = ({ form }: Props) => {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Password (Optional)</FormLabel>
|
<FormLabel>Password (Optional)</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput
|
<SecretInput placeholder="••••••••" value={field.value ?? ""} onChange={field.onChange} />
|
||||||
placeholder="••••••••"
|
|
||||||
value={field.value ?? ""}
|
|
||||||
onChange={field.onChange}
|
|
||||||
isDirty={form.getFieldState("password", form.formState).isDirty}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Password for WebDAV authentication (optional).</FormDescription>
|
<FormDescription>Password for WebDAV authentication (optional).</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue