feat: add redirect from index to single customer form
This commit is contained in:
@@ -16,10 +16,12 @@ import {
|
|||||||
CustomerFormSchema
|
CustomerFormSchema
|
||||||
} from '@utils/types';
|
} from '@utils/types';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { FormProvider, useForm } from 'react-hook-form';
|
import { FormProvider, useForm } from 'react-hook-form';
|
||||||
|
|
||||||
export default function CustomerForms() {
|
export default function CustomerForms() {
|
||||||
|
const router = useRouter();
|
||||||
const [customerForms, setCustomerForms] = useState<CustomerForm[]>([]);
|
const [customerForms, setCustomerForms] = useState<CustomerForm[]>([]);
|
||||||
|
|
||||||
const form = useForm<CustomerFormCreate>({
|
const form = useForm<CustomerFormCreate>({
|
||||||
@@ -47,9 +49,11 @@ export default function CustomerForms() {
|
|||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
async function handleSubmit(values: CustomerFormCreate) {
|
const redirectToCustomerForm = (id: string) => {
|
||||||
console.log('values', values);
|
router.push(`/customer-form/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function handleSubmit(values: CustomerFormCreate) {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
'/api/protected/customer-form',
|
'/api/protected/customer-form',
|
||||||
@@ -64,8 +68,6 @@ export default function CustomerForms() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('response', response.data.data);
|
|
||||||
|
|
||||||
const validatedResponse = CustomerFormSchema.safeParse(
|
const validatedResponse = CustomerFormSchema.safeParse(
|
||||||
response.data.data
|
response.data.data
|
||||||
);
|
);
|
||||||
@@ -86,9 +88,12 @@ export default function CustomerForms() {
|
|||||||
<h1>Forms</h1>
|
<h1>Forms</h1>
|
||||||
{customerForms &&
|
{customerForms &&
|
||||||
customerForms.map(customerForm => (
|
customerForms.map(customerForm => (
|
||||||
<div key={customerForm.id}>
|
<div
|
||||||
<h2>{customerForm.type}</h2>
|
onClick={() => redirectToCustomerForm(customerForm.id)}
|
||||||
<p>{customerForm.text}</p>
|
key={customerForm.id}
|
||||||
|
>
|
||||||
|
{customerForm.text}
|
||||||
|
of type {customerForm.type}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
<h1>New form</h1>
|
<h1>New form</h1>
|
||||||
|
|||||||
Reference in New Issue
Block a user