Skip to content

Commit

Permalink
adjustments based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
SachiGoto committed Feb 26, 2024
1 parent 33c3fd9 commit 5e1699d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/account/edit/components/account-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { useUserId } from '@/providers/session-provider'
import { useUploadFile, useUserUpdate, useUserGet } from '../../hooks'

export type UserDetailsProps = {
name: string | undefined
email: string | undefined
name: string
email: string
profile_picture_url: string | undefined | null
}

Expand Down
7 changes: 6 additions & 1 deletion app/account/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export default function AccountEditPage() {
const color = useColorModeValue('black', 'gray.300')
const { userData, isUserLoading } = useUserGet()
return (
<Box as="main" minH="100svh" bg={bg} color={color}>
<Box
as="main"
minH={{ base: 'calc(100vh - 120px)', md: 'calc(100vh - 170px)' }}
bg={bg}
color={color}
>
<Container
minW={{ base: '100%', lg: 'container.sm' }}
display="flex"
Expand Down
20 changes: 17 additions & 3 deletions app/account/hooks/useUploadFile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useState } from 'react'
import { useToast } from '@chakra-ui/react'
import { createClient } from '@supabase/supabase-js'
import { updateImageMetadataAction } from '../action/update-image-metadata'

export const useUploadFile = () => {
const [isLoading, setIsLoading] = useState(false)

const toast = useToast()
const uploadFile = async (
profile_picture_url: string | null,
selectedImage: File,
Expand All @@ -29,10 +30,23 @@ export const useUploadFile = () => {
const { data: uploadData, error: uploadError } = await supabase.storage
.from('tabi-memo-uploads')
.upload(`account/edit/${selectedImage.name}`, selectedImage, {
contentType: selectedImage.type
upsert: true
})

if (uploadError) throw new Error(uploadError.message)
if (uploadError) {
toast({
title: "We're sorry, but you failed to upload your profile image",
description:
uploadError instanceof Error
? uploadError.message
: 'Please try again later.',
status: 'error',
duration: 5000,
isClosable: true,
position: 'top'
})
throw new Error(uploadError.message)
}

await updateImageMetadataAction(userId, uploadData.path)

Expand Down

0 comments on commit 5e1699d

Please sign in to comment.