Skip to content

Commit

Permalink
Merge pull request #38 from arkews/develop
Browse files Browse the repository at this point in the history
new release
  • Loading branch information
CarlosPavajeau authored Dec 29, 2022
2 parents 0068e8a + 254a60a commit 9041b92
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 95 deletions.
26 changes: 11 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,30 @@

## [1.7.0](https://github.com/arkews/joshub/compare/v1.6.0...v1.7.0) (2022-12-29)


### Features

* add session check logic ([a836245](https://github.com/arkews/joshub/commit/a83624549aaca1c88f28357820f972006315d422))

- add session check logic ([a836245](https://github.com/arkews/joshub/commit/a83624549aaca1c88f28357820f972006315d422))

### Bug Fixes

* avoid unnecessary redirections in the verification of the existence of a pub ([be2495c](https://github.com/arkews/joshub/commit/be2495cc60e693bb89c45b7f39c28471d1f22844))
- avoid unnecessary redirections in the verification of the existence of a pub ([be2495c](https://github.com/arkews/joshub/commit/be2495cc60e693bb89c45b7f39c28471d1f22844))

## [1.6.0](https://github.com/arkews/joshub/compare/v1.5.1...v1.6.0) (2022-12-28)


### Features

* add find customer by id api endpoint ([f62186a](https://github.com/arkews/joshub/commit/f62186a03e3e3cdad48960b7c42d53b1dafd293d))
* **employees:** new register employee form ui ([ad3b233](https://github.com/arkews/joshub/commit/ad3b233f3c0f4fb468c5ae22997112b9815f8849))
* new customer field ui ([44c5a6a](https://github.com/arkews/joshub/commit/44c5a6ad632e8b9d90b2e0cd86965f4fdf99c96c))
* **products:** add new register form ui ([cc42c55](https://github.com/arkews/joshub/commit/cc42c556b56c07dcad7790fa4fc98b3e18337e22))
* **sales:** new orders form ([e70b09e](https://github.com/arkews/joshub/commit/e70b09eaaf056d0579bd274b491daed64231d03a))
* **sales:** new sales form ([bed19c0](https://github.com/arkews/joshub/commit/bed19c020abda008b0b7852037b63051d3536667))
* **transaction-details:** add detail card ([601f5cd](https://github.com/arkews/joshub/commit/601f5cd33ffe3327a91142daf8cc64537602bddc))
* **transaction-details:** add remove detail support ([94bf227](https://github.com/arkews/joshub/commit/94bf227a0662e674a5fe45dc753f6f4962ae7e35))

- add find customer by id api endpoint ([f62186a](https://github.com/arkews/joshub/commit/f62186a03e3e3cdad48960b7c42d53b1dafd293d))
- **employees:** new register employee form ui ([ad3b233](https://github.com/arkews/joshub/commit/ad3b233f3c0f4fb468c5ae22997112b9815f8849))
- new customer field ui ([44c5a6a](https://github.com/arkews/joshub/commit/44c5a6ad632e8b9d90b2e0cd86965f4fdf99c96c))
- **products:** add new register form ui ([cc42c55](https://github.com/arkews/joshub/commit/cc42c556b56c07dcad7790fa4fc98b3e18337e22))
- **sales:** new orders form ([e70b09e](https://github.com/arkews/joshub/commit/e70b09eaaf056d0579bd274b491daed64231d03a))
- **sales:** new sales form ([bed19c0](https://github.com/arkews/joshub/commit/bed19c020abda008b0b7852037b63051d3536667))
- **transaction-details:** add detail card ([601f5cd](https://github.com/arkews/joshub/commit/601f5cd33ffe3327a91142daf8cc64537602bddc))
- **transaction-details:** add remove detail support ([94bf227](https://github.com/arkews/joshub/commit/94bf227a0662e674a5fe45dc753f6f4962ae7e35))

### Refactors

* remove unused component and page ([fd805ef](https://github.com/arkews/joshub/commit/fd805efb23ad5a6a4ae527c70f5fab0d9d52dc75))
- remove unused component and page ([fd805ef](https://github.com/arkews/joshub/commit/fd805efb23ad5a6a4ae527c70f5fab0d9d52dc75))

## [1.5.1](https://github.com/arkews/joshub/compare/v1.5.0...v1.5.1) (2022-12-27)

Expand Down
216 changes: 144 additions & 72 deletions components/pubs/register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,39 @@ import { PubInputs } from '@joshub/types/pubs'
import { useRouter } from 'next/router'
import { FC, useEffect } from 'react'
import { useUser } from '@supabase/auth-helpers-react'
import { z } from 'zod'
import { zodResolver } from '@hookform/resolvers/zod'

const PubSchema = z.object({
name: z.string().min(1, 'El nombre es requerido'),
address: z.string().min(1, 'La dirección es requerida'),
user_id: z.string().min(1, 'El dueño es requerido'),
owner: z.object({
id: z.string().min(1, 'La identificación es requerida'),
name: z.string().min(1, 'El nombre es requerido'),
phone: z.string().min(1, 'El teléfono es requerido'),
salary: z.coerce.number().min(1, 'El salario es requerido')
})
})

const RegisterPubForm: FC = () => {
const user = useUser()
const {
register,
setValue,
handleSubmit,
formState: { errors }
formState: { errors, isSubmitting }
} = useForm<PubInputs>({
resolver: zodResolver(PubSchema),
defaultValues: {
owner: user?.id,
user_id: user?.id,
nit: undefined
}
})

useEffect(() => {
if (user !== undefined && user !== null) {
setValue('owner', user.id)
setValue('user_id', user.id)
}
}, [user])

Expand All @@ -31,7 +46,7 @@ const RegisterPubForm: FC = () => {
}

const router = useRouter()
const { mutate, isLoading, error } = useMutation(savePub, {
const { mutate, isLoading } = useMutation(savePub, {
onSuccess: () => {
void router.push('/dashboard')
}
Expand All @@ -44,91 +59,148 @@ const RegisterPubForm: FC = () => {
}

return (
<div className='mt-5'>
<form onSubmit={handleSubmit(onSubmit)}>
<div className='sm:shadow sm:rounded-md'>
<div className='bg-white sm:px-4 py-5 sm:p-6'>
<div className='grid grid-cols-6 gap-6'>
<div className='col-span-6'>
<label
htmlFor='name'
className='block text-sm font-medium text-gray-700'
>
Nombre
</label>
<form className='space-y-10' onSubmit={handleSubmit(onSubmit)}>
<div>
<div className='grid grid-cols-6 gap-6'>
<div className='col-span-6 sm:col-span-3'>
<h3 className='text-2xl text-gray-900 mb-3'>Bar</h3>

<div>
<label className='block'>
<span className='block'>Nombre</span>
<input
type='text'
className='mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm'
id='name'
{...register('name', { required: true })}
className='block border text-lg px-4 py-3 mt-2 rounded-lg border-gray-200 focus:bg-white text-gray-900 focus:border-blue-600 focus:ring-0 outline-none w-full disabled:bg-gray-100 disabled:text-gray-400 disabled:cursor-not-allowed'
{...register('name')}
disabled={isSubmitting || isLoading}
/>
</label>
{errors.name != null && (
<p className='text-sm text-red-600 mt-1'>
{errors.name.message}
</p>
)}
</div>

{errors.name != null && (
<span className='text-red-400 text-xs block py-1'>
Este campo es requerido
</span>
)}
</div>

<div className='col-span-6'>
<label
htmlFor='nit'
className='block text-sm font-medium text-gray-700'
>
Nit
</label>
<div className='mt-6'>
<label className='block'>
<span className='block'>Nit</span>
<input
type='text'
className='mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm'
id='nit'
className='block border text-lg px-4 py-3 mt-2 rounded-lg border-gray-200 focus:bg-white text-gray-900 focus:border-blue-600 focus:ring-0 outline-none w-full disabled:bg-gray-100 disabled:text-gray-400 disabled:cursor-not-allowed'
{...register('nit')}
disabled={isSubmitting || isLoading}
/>
</label>
{errors.nit != null && (
<p className='text-sm text-red-600 mt-1'>
{errors.nit.message}
</p>
)}
</div>

<div className='mt-6'>
<label className='block'>
<span className='block'>Dirección</span>
<input
type='text'
className='block border text-lg px-4 py-3 mt-2 rounded-lg border-gray-200 focus:bg-white text-gray-900 focus:border-blue-600 focus:ring-0 outline-none w-full disabled:bg-gray-100 disabled:text-gray-400 disabled:cursor-not-allowed'
{...register('address')}
disabled={isSubmitting || isLoading}
/>
</label>
{errors.address != null && (
<p className='text-sm text-red-600 mt-1'>
{errors.address.message}
</p>
)}
</div>
</div>

<div className='col-span-6 sm:col-span-3'>
<h3 className='text-2xl text-gray-900 mb-3'>Propietario</h3>

<div>
<label className='block'>
<span className='block'>Identificación del propietario</span>
<input
type='text'
className='block border text-lg px-4 py-3 mt-2 rounded-lg border-gray-200 focus:bg-white text-gray-900 focus:border-blue-600 focus:ring-0 outline-none w-full disabled:bg-gray-100 disabled:text-gray-400 disabled:cursor-not-allowed'
{...register('owner.id')}
disabled={isSubmitting || isLoading}
/>
</div>

<div className='col-span-6'>
<label
htmlFor='address'
className='block text-sm font-medium text-gray-700'
>
Dirección
</label>
</label>
{errors.owner?.id != null && (
<p className='text-sm text-red-600 mt-1'>
{errors.owner.id.message}
</p>
)}
</div>

<div className='mt-6'>
<label className='block'>
<span className='block'>Nombre del propietario</span>
<input
type='text'
className='mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm'
id='address'
{...register('address', { required: true })}
className='block border text-lg px-4 py-3 mt-2 rounded-lg border-gray-200 focus:bg-white text-gray-900 focus:border-blue-600 focus:ring-0 outline-none w-full disabled:bg-gray-100 disabled:text-gray-400 disabled:cursor-not-allowed'
{...register('owner.name')}
disabled={isSubmitting || isLoading}
/>
</label>
{errors.owner?.name != null && (
<p className='text-sm text-red-600 mt-1'>
{errors.owner.name.message}
</p>
)}
</div>

{errors.address != null && (
<span className='text-red-400 text-xs block py-1'>
Este campo es requerido
</span>
)}
</div>

{Boolean(error) && (
<div
className='p-4 w-full col-span-6 mt-3 text-sm text-red-700 bg-red-100 rounded-lg dark:bg-red-200 dark:text-red-800'
role='alert'
>
Error al registrar el bar.
</div>
<div className='mt-6'>
<label className='block'>
<span className='block'>Teléfono del propietario</span>
<input
type='text'
className='block border text-lg px-4 py-3 mt-2 rounded-lg border-gray-200 focus:bg-white text-gray-900 focus:border-blue-600 focus:ring-0 outline-none w-full disabled:bg-gray-100 disabled:text-gray-400 disabled:cursor-not-allowed'
{...register('owner.phone')}
disabled={isSubmitting || isLoading}
/>
</label>
{errors.owner?.phone != null && (
<p className='text-sm text-red-600 mt-1'>
{errors.owner.phone.message}
</p>
)}
</div>

<div className='py-3 col-span-6'>
<button
type='submit'
className='inline-flex w-full justify-center rounded-full border border-transparent bg-indigo-100 px-4 py-2 text-sm font-medium text-indigo-900 hover:bg-indigo-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 focus-visible:ring-offset-2 disabled:bg-gray-200 disabled:text-gray-400'
disabled={isLoading}
>
Registrar
</button>
</div>
<div className='mt-6'>
<label className='block'>
<span className='block'>Salario del propietario</span>
<input
type='text'
className='block border text-lg px-4 py-3 mt-2 rounded-lg border-gray-200 focus:bg-white text-gray-900 focus:border-blue-600 focus:ring-0 outline-none w-full disabled:bg-gray-100 disabled:text-gray-400 disabled:cursor-not-allowed'
{...register('owner.salary')}
disabled={isSubmitting || isLoading}
/>
</label>
{errors.owner?.salary != null && (
<p className='text-sm text-red-600 mt-1'>
{errors.owner.salary.message}
</p>
)}
</div>
</div>
</div>
</form>
</div>

<div className='mt-8'>
<button
type='submit'
className='text-base w-full px-6 py-3.5 font-medium text-center text-indigo-900 bg-indigo-100 rounded-full hover:bg-indigo-200 border border-transparent disabled:bg-gray-100 disabled:text-gray-400'
disabled={isSubmitting || isLoading}
>
Registrar
</button>
</div>
</div>
</form>
)
}

Expand Down
38 changes: 34 additions & 4 deletions pages/api/pubs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,53 @@ const handler = async (
res: NextApiResponse
): Promise<void> => {
if (req.method === 'POST') {
const supabase = createServerSupabaseClient({ req, res })
const supabase = createServerSupabaseClient({
req,
res
})

const { body } = req
const { owner, user_id: userId, ...rest } = body
const pub = {
...rest,
owner: userId
}

const { data, error } = await supabase.from('pubs').insert(body).select()
const { data, error } = await supabase.from('pubs').insert(pub).select()

if (error != null) {
res.status(500).json({ error: error.message })
return
}

res.status(200).json(data)
const pubId = data[0].id

const { error: ownerError } = await supabase
.from('employees')
.insert({
...owner,
pub_id: pubId,
user_id: userId
})
.select()

if (ownerError != null) {
// delete the pub
await supabase.from('pubs').delete().eq('id', pubId)

res.status(500).json({ error: ownerError.message })
return
}

res.status(200).json(data[0])
return
}

if (req.method === 'GET') {
const supabase = createServerSupabaseClient({ req, res })
const supabase = createServerSupabaseClient({
req,
res
})

const { owner } = req.query

Expand Down
8 changes: 5 additions & 3 deletions pages/pubs/register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ const RegisterPubPage: NextPage = () => {
)}
{!isLoading && pubs === undefined && (
<>
<div className='mb-5'>
<h1 className='text-4xl text-center text-gray-700 font-light'>
<div className='bg-white p-8 py-12 rounded-lg shadow-xl'>
<h1 className='text-gray-900 font-bold text-3xl'>
Registrar bar
</h1>
<p className='text-gray-600 mt-4 mb-8 leading-relaxed'></p>

<RegisterPubForm />
</div>
<RegisterPubForm />
</>
)}
</div>
Expand Down
Loading

1 comment on commit 9041b92

@vercel
Copy link

@vercel vercel bot commented on 9041b92 Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

joshub – ./

joshub.vercel.app
joshub-arkews.vercel.app
joshub-git-main-arkews.vercel.app

Please sign in to comment.