diff --git a/web/src/actions/account.ts b/web/src/actions/account.ts index 38d3ae8..b1e3533 100644 --- a/web/src/actions/account.ts +++ b/web/src/actions/account.ts @@ -159,6 +159,7 @@ export const accountActions = { .optional() .nullable(), pictureFile: imageFileSchema, + removePicture: z.coerce.boolean().default(false), }), handler: async (input, context) => { if (input.id !== context.locals.user.id) { @@ -204,14 +205,14 @@ export const accountActions = { input.pictureFile.name, `users/pictures/${String(context.locals.user.id)}` ) - : null + : undefined const user = await prisma.user.update({ where: { id: context.locals.user.id }, data: { displayName: input.displayName ?? null, link: input.link ?? null, - picture: pictureUrl, + picture: input.removePicture ? null : (pictureUrl ?? undefined), }, }) diff --git a/web/src/components/InputFile.astro b/web/src/components/InputFile.astro index 9ece642..c0a27c7 100644 --- a/web/src/components/InputFile.astro +++ b/web/src/components/InputFile.astro @@ -10,15 +10,27 @@ type Props = Omit, 'children' | 'inputId'> & accept?: string disabled?: boolean multiple?: boolean + removeCheckbox?: { + name: string + label: string + } } -const { accept, disabled, multiple, ...wrapperProps } = Astro.props +const { accept, disabled, multiple, removeCheckbox, ...wrapperProps } = Astro.props const inputId = Astro.locals.makeId(`input-${wrapperProps.name}`) const hasError = !!wrapperProps.error && wrapperProps.error.length > 0 --- + { + !!removeCheckbox && ( + + ) + } 0 baseInputClassNames.input, baseInputClassNames.file, hasError && baseInputClassNames.error, - disabled && baseInputClassNames.disabled + disabled && baseInputClassNames.disabled, + '[&:is(:has([data-remove-checkbox]:checked)_~_*)]:hidden' )} required={wrapperProps.required} disabled={disabled} diff --git a/web/src/components/InputImageFile.astro b/web/src/components/InputImageFile.astro index b73e274..37c48ec 100644 --- a/web/src/components/InputImageFile.astro +++ b/web/src/components/InputImageFile.astro @@ -8,20 +8,26 @@ import type { ComponentProps } from 'astro/types' type Props = Omit, 'accept'> & { square?: boolean + value?: string | null } -const { class: className, square, ...inputFileProps } = Astro.props +const { class: className, square, value, ...inputFileProps } = Astro.props ---
- + Preview
diff --git a/web/src/components/InputWrapper.astro b/web/src/components/InputWrapper.astro index 463b8af..ac092a4 100644 --- a/web/src/components/InputWrapper.astro +++ b/web/src/components/InputWrapper.astro @@ -66,7 +66,7 @@ const hasError = !!error && error.length > 0 { !!description && ( -
+
) diff --git a/web/src/pages/account/edit.astro b/web/src/pages/account/edit.astro index 6dcb57d..489ba41 100644 --- a/web/src/pages/account/edit.astro +++ b/web/src/pages/account/edit.astro @@ -1,8 +1,9 @@ --- -import { Icon } from 'astro-icon/components' import { actions, isInputError } from 'astro:actions' import Button from '../../components/Button.astro' +import InputImageFile from '../../components/InputImageFile.astro' +import InputText from '../../components/InputText.astro' import { karmaUnlocksById } from '../../constants/karmaUnlocks' import MiniLayout from '../../layouts/MiniLayout.astro' import { makeKarmaUnlockMessage } from '../../lib/karmaUnlocks' @@ -42,95 +43,52 @@ const inputErrors = isInputError(result?.error) ? result.error.fields : {}
-
- - - { - inputErrors.displayName && ( -

{inputErrors.displayName.join(', ')}

- ) - } - { - !user.karmaUnlocks.displayName && ( -

- - {makeKarmaUnlockMessage(karmaUnlocksById.displayName)} - - Learn about karma - -

- ) - } -
+ -
- - - {inputErrors.link &&

{inputErrors.link.join(', ')}

} - { - !user.karmaUnlocks.websiteLink && ( -

- - {makeKarmaUnlockMessage(karmaUnlocksById.websiteLink)} - - Learn about karma - -

- ) - } -
+ -
- -
- -

- Upload a square image for best results. Supported formats: JPG, PNG, WebP, AVIF, JXL. Max size: 5MB. -

-
- { - inputErrors.pictureFile && ( -

{inputErrors.pictureFile.join(', ')}

- ) - } - { - !user.karmaUnlocks.profilePicture && ( -

- - You need 200 karma to have a profile picture. - - Learn about karma - -

- ) - } -
+