From 62c200b543aff4fb0758d84e528b65fa7f965685 Mon Sep 17 00:00:00 2001 From: shinework Date: Sun, 28 Apr 2024 18:15:18 +0200 Subject: [PATCH] fix: contact form --- back/api/contact/config/routes.json | 12 + back/api/contact/controllers/contact.js | 4 +- .../contact/documentation/1.0.0/contact.json | 448 ----------------- .../1.0.0/full_documentation.json | 450 +----------------- web/api/client-api.ts | 3 +- web/pages/contact.tsx | 25 +- 6 files changed, 28 insertions(+), 914 deletions(-) create mode 100644 back/api/contact/config/routes.json diff --git a/back/api/contact/config/routes.json b/back/api/contact/config/routes.json new file mode 100644 index 00000000..86d14196 --- /dev/null +++ b/back/api/contact/config/routes.json @@ -0,0 +1,12 @@ +{ + "routes": [ + { + "method": "POST", + "path": "/contacts", + "handler": "contact.create", + "config": { + "policies": [] + } + } + ] +} diff --git a/back/api/contact/controllers/contact.js b/back/api/contact/controllers/contact.js index 2788a4ae..f0af47bc 100644 --- a/back/api/contact/controllers/contact.js +++ b/back/api/contact/controllers/contact.js @@ -24,8 +24,8 @@ module.exports = { await strapi.plugins["email"].services.email.sendTemplatedEmail( { - to: "gesnault@premieroctet.com", - from: entity.from, + from: process.env.EMAIL_SENDER, + to: process.env.EMAIL_SENDER, }, template, { diff --git a/back/api/contact/documentation/1.0.0/contact.json b/back/api/contact/documentation/1.0.0/contact.json index 119f4ef9..55794f52 100644 --- a/back/api/contact/documentation/1.0.0/contact.json +++ b/back/api/contact/documentation/1.0.0/contact.json @@ -1,197 +1,6 @@ { "paths": { "/contacts": { - "get": { - "deprecated": false, - "description": "", - "responses": { - "200": { - "description": "response", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Contact" - } - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "parameters": [ - { - "name": "_limit", - "in": "query", - "required": false, - "description": "Maximum number of results possible", - "schema": { - "type": "integer" - }, - "deprecated": false - }, - { - "name": "_sort", - "in": "query", - "required": false, - "description": "Sort according to a specific field.", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_start", - "in": "query", - "required": false, - "description": "Skip a specific number of entries (especially useful for pagination)", - "schema": { - "type": "integer" - }, - "deprecated": false - }, - { - "name": "=", - "in": "query", - "required": false, - "description": "Get entries that matches exactly your input", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_ne", - "in": "query", - "required": false, - "description": "Get records that are not equals to something", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_lt", - "in": "query", - "required": false, - "description": "Get record that are lower than a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_lte", - "in": "query", - "required": false, - "description": "Get records that are lower than or equal to a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_gt", - "in": "query", - "required": false, - "description": "Get records that are greater than a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_gte", - "in": "query", - "required": false, - "description": "Get records that are greater than or equal a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_contains", - "in": "query", - "required": false, - "description": "Get records that contains a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_containss", - "in": "query", - "required": false, - "description": "Get records that contains (case sensitive) a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_in", - "in": "query", - "required": false, - "description": "Get records that matches any value in the array of values", - "schema": { - "type": "array", - "items": { - "type": "string" - } - }, - "deprecated": false - }, - { - "name": "_nin", - "in": "query", - "required": false, - "description": "Get records that doesn't match any value in the array of values", - "schema": { - "type": "array", - "items": { - "type": "string" - } - }, - "deprecated": false - } - ] - }, "post": { "deprecated": false, "description": "Create a new record", @@ -253,263 +62,6 @@ } } } - }, - "/contacts/count": { - "get": { - "deprecated": false, - "description": "", - "responses": { - "200": { - "description": "response", - "content": { - "application/json": { - "schema": { - "properties": { - "count": { - "type": "integer" - } - } - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "parameters": [] - } - }, - "/contacts/{id}": { - "get": { - "deprecated": false, - "description": "", - "responses": { - "200": { - "description": "response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Contact" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "parameters": [ - { - "name": "id", - "in": "path", - "description": "", - "deprecated": false, - "required": true, - "schema": { - "type": "string" - } - } - ] - }, - "put": { - "deprecated": false, - "description": "Update a record", - "responses": { - "200": { - "description": "response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Contact" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "requestBody": { - "description": "", - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/NewContact" - } - } - } - }, - "parameters": [ - { - "name": "id", - "in": "path", - "description": "", - "deprecated": false, - "required": true, - "schema": { - "type": "string" - } - } - ] - }, - "delete": { - "deprecated": false, - "description": "Delete a record", - "responses": { - "200": { - "description": "deletes a single record based on the ID supplied", - "content": { - "application/json": { - "schema": { - "type": "integer", - "format": "int64" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "parameters": [ - { - "name": "id", - "in": "path", - "description": "", - "deprecated": false, - "required": true, - "schema": { - "type": "string" - } - } - ] - } } }, "components": { diff --git a/back/extensions/documentation/documentation/1.0.0/full_documentation.json b/back/extensions/documentation/documentation/1.0.0/full_documentation.json index 3863c633..226310e4 100644 --- a/back/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/back/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "03/18/2024 6:34:37 PM" + "x-generation-date": "04/28/2024 6:17:11 PM" }, "x-strapi-config": { "path": "/documentation", @@ -3022,197 +3022,6 @@ } }, "/contacts": { - "get": { - "deprecated": false, - "description": "", - "responses": { - "200": { - "description": "response", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Contact" - } - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "parameters": [ - { - "name": "_limit", - "in": "query", - "required": false, - "description": "Maximum number of results possible", - "schema": { - "type": "integer" - }, - "deprecated": false - }, - { - "name": "_sort", - "in": "query", - "required": false, - "description": "Sort according to a specific field.", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_start", - "in": "query", - "required": false, - "description": "Skip a specific number of entries (especially useful for pagination)", - "schema": { - "type": "integer" - }, - "deprecated": false - }, - { - "name": "=", - "in": "query", - "required": false, - "description": "Get entries that matches exactly your input", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_ne", - "in": "query", - "required": false, - "description": "Get records that are not equals to something", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_lt", - "in": "query", - "required": false, - "description": "Get record that are lower than a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_lte", - "in": "query", - "required": false, - "description": "Get records that are lower than or equal to a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_gt", - "in": "query", - "required": false, - "description": "Get records that are greater than a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_gte", - "in": "query", - "required": false, - "description": "Get records that are greater than or equal a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_contains", - "in": "query", - "required": false, - "description": "Get records that contains a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_containss", - "in": "query", - "required": false, - "description": "Get records that contains (case sensitive) a value", - "schema": { - "type": "string" - }, - "deprecated": false - }, - { - "name": "_in", - "in": "query", - "required": false, - "description": "Get records that matches any value in the array of values", - "schema": { - "type": "array", - "items": { - "type": "string" - } - }, - "deprecated": false - }, - { - "name": "_nin", - "in": "query", - "required": false, - "description": "Get records that doesn't match any value in the array of values", - "schema": { - "type": "array", - "items": { - "type": "string" - } - }, - "deprecated": false - } - ] - }, "post": { "deprecated": false, "description": "Create a new record", @@ -3275,263 +3084,6 @@ } } }, - "/contacts/count": { - "get": { - "deprecated": false, - "description": "", - "responses": { - "200": { - "description": "response", - "content": { - "application/json": { - "schema": { - "properties": { - "count": { - "type": "integer" - } - } - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "parameters": [] - } - }, - "/contacts/{id}": { - "get": { - "deprecated": false, - "description": "", - "responses": { - "200": { - "description": "response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Contact" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "parameters": [ - { - "name": "id", - "in": "path", - "description": "", - "deprecated": false, - "required": true, - "schema": { - "type": "string" - } - } - ] - }, - "put": { - "deprecated": false, - "description": "Update a record", - "responses": { - "200": { - "description": "response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Contact" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "requestBody": { - "description": "", - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/NewContact" - } - } - } - }, - "parameters": [ - { - "name": "id", - "in": "path", - "description": "", - "deprecated": false, - "required": true, - "schema": { - "type": "string" - } - } - ] - }, - "delete": { - "deprecated": false, - "description": "Delete a record", - "responses": { - "200": { - "description": "deletes a single record based on the ID supplied", - "content": { - "application/json": { - "schema": { - "type": "integer", - "format": "int64" - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "default": { - "description": "unexpected error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "summary": "", - "tags": [ - "Contact" - ], - "parameters": [ - { - "name": "id", - "in": "path", - "description": "", - "deprecated": false, - "required": true, - "schema": { - "type": "string" - } - } - ] - } - }, "/disponibilities": { "get": { "deprecated": false, diff --git a/web/api/client-api.ts b/web/api/client-api.ts index 9d7a06bf..65b96b48 100644 --- a/web/api/client-api.ts +++ b/web/api/client-api.ts @@ -12,6 +12,5 @@ export const client = new Api({ Authorization: `Bearer ${session.user.jwt}`, }, } - } + }, }) - diff --git a/web/pages/contact.tsx b/web/pages/contact.tsx index b9a7a214..9ce8fb27 100644 --- a/web/pages/contact.tsx +++ b/web/pages/contact.tsx @@ -1,29 +1,28 @@ -import React, { useState } from 'react' -import { SSRConfig } from 'next-i18next' -import { GetServerSideProps } from 'next' -import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { - Text, - Input, - Textarea, Button, Container, + Flex, Heading, + Input, + Text, + Textarea, VStack, - Flex, } from '@chakra-ui/react' -import { useTranslation } from 'next-i18next' import { yupResolver } from '@hookform/resolvers/yup' -import * as yup from 'yup' +import { GetServerSideProps } from 'next' +import { SSRConfig, useTranslation } from 'next-i18next' +import { serverSideTranslations } from 'next-i18next/serverSideTranslations' +import { NextSeo } from 'next-seo' +import { useState } from 'react' import { useForm } from 'react-hook-form' +import * as yup from 'yup' +import { client } from '~api/client-api' import FormField from '~components/FormField' import MessageSent from '~components/MessageSent' -import useToast from '~hooks/useToast' import { ROUTE_CONTACT } from '~constants' +import useToast from '~hooks/useToast' import { Page } from '~typings/api' -import { client } from '~api/client-api' import { getPage } from '~utils/page' -import { NextSeo } from 'next-seo' const Contact = ({ page }: { page?: Page }) => { const { errorToast } = useToast()