diff --git a/back/api/application/config/policies/can-update.js b/back/api/application/config/policies/can-update.js index 1a757a0..67ffc1a 100644 --- a/back/api/application/config/policies/can-update.js +++ b/back/api/application/config/policies/can-update.js @@ -1,20 +1,20 @@ module.exports = async (ctx, next) => { - const { id } = ctx.params; + const { id } = ctx.params if (id && ctx.state.user) { - const { user } = ctx.state; + const { user } = ctx.state - const application = await strapi - .query("application") - .findOne( - { id } - ) + const application = await strapi.query('application').findOne({ id }) // Only application place can update application status - if(application && application?.espace?.users_permissions_user === user.id){ - return await next(); + if ( + application && + (application?.espace?.users_permissions_user === user.id || + application?.company?.id === user.id) + ) { + return await next() } } - ctx.unauthorized(`Not allowed`); -}; + ctx.unauthorized(`Not allowed`) +} 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 365daa9..592c620 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/04/2024 1:59:48 PM" + "x-generation-date": "03/04/2024 7:16:07 PM" }, "x-strapi-config": { "path": "/documentation", @@ -95,9 +95,7 @@ } }, "summary": "", - "tags": [ - "Actuality" - ], + "tags": ["Actuality"], "parameters": [ { "name": "_limit", @@ -283,9 +281,7 @@ } }, "summary": "", - "tags": [ - "Actuality" - ], + "tags": ["Actuality"], "requestBody": { "description": "", "required": true, @@ -350,9 +346,7 @@ } }, "summary": "", - "tags": [ - "Actuality" - ], + "tags": ["Actuality"], "parameters": [] } }, @@ -403,9 +397,7 @@ } }, "summary": "", - "tags": [ - "Actuality" - ], + "tags": ["Actuality"], "parameters": [ { "name": "id", @@ -465,9 +457,7 @@ } }, "summary": "", - "tags": [ - "Actuality" - ], + "tags": ["Actuality"], "requestBody": { "description": "", "required": true, @@ -539,9 +529,7 @@ } }, "summary": "", - "tags": [ - "Actuality" - ], + "tags": ["Actuality"], "parameters": [ { "name": "id", @@ -606,9 +594,7 @@ } }, "summary": "", - "tags": [ - "Application" - ], + "tags": ["Application"], "parameters": [ { "name": "campaignId", @@ -810,9 +796,7 @@ } }, "summary": "", - "tags": [ - "Application" - ], + "tags": ["Application"], "parameters": [ { "name": "_limit", @@ -998,9 +982,7 @@ } }, "summary": "", - "tags": [ - "Application" - ], + "tags": ["Application"], "requestBody": { "description": "", "required": true, @@ -1065,9 +1047,7 @@ } }, "summary": "", - "tags": [ - "Application" - ], + "tags": ["Application"], "parameters": [] } }, @@ -1118,9 +1098,7 @@ } }, "summary": "", - "tags": [ - "Application" - ], + "tags": ["Application"], "parameters": [ { "name": "id", @@ -1180,9 +1158,7 @@ } }, "summary": "", - "tags": [ - "Application" - ], + "tags": ["Application"], "requestBody": { "description": "", "required": true, @@ -1254,9 +1230,7 @@ } }, "summary": "", - "tags": [ - "Application" - ], + "tags": ["Application"], "parameters": [ { "name": "id", @@ -1321,9 +1295,7 @@ } }, "summary": "", - "tags": [ - "Booking" - ], + "tags": ["Booking"], "parameters": [ { "name": "bookingType", @@ -1333,11 +1305,7 @@ "required": true, "schema": { "type": "string", - "enum": [ - "all", - "request", - "booking" - ] + "enum": ["all", "request", "booking"] } } ], @@ -1394,9 +1362,7 @@ } }, "summary": "", - "tags": [ - "Booking" - ], + "tags": ["Booking"], "parameters": [ { "name": "_limit", @@ -1582,9 +1548,7 @@ } }, "summary": "", - "tags": [ - "Booking" - ], + "tags": ["Booking"], "requestBody": { "description": "", "required": true, @@ -1649,9 +1613,7 @@ } }, "summary": "", - "tags": [ - "Booking" - ], + "tags": ["Booking"], "parameters": [] } }, @@ -1702,9 +1664,7 @@ } }, "summary": "", - "tags": [ - "Booking" - ], + "tags": ["Booking"], "parameters": [ { "name": "id", @@ -1764,9 +1724,7 @@ } }, "summary": "", - "tags": [ - "Booking" - ], + "tags": ["Booking"], "requestBody": { "description": "", "required": true, @@ -1838,9 +1796,7 @@ } }, "summary": "", - "tags": [ - "Booking" - ], + "tags": ["Booking"], "parameters": [ { "name": "id", @@ -1906,9 +1862,7 @@ } }, "summary": "", - "tags": [ - "Booking" - ], + "tags": ["Booking"], "requestBody": { "description": "", "required": true, @@ -1992,9 +1946,7 @@ } }, "summary": "", - "tags": [ - "Campaign" - ], + "tags": ["Campaign"], "parameters": [ { "name": "_limit", @@ -2180,9 +2132,7 @@ } }, "summary": "", - "tags": [ - "Campaign" - ], + "tags": ["Campaign"], "requestBody": { "description": "", "required": true, @@ -2247,9 +2197,7 @@ } }, "summary": "", - "tags": [ - "Campaign" - ], + "tags": ["Campaign"], "parameters": [] } }, @@ -2300,9 +2248,7 @@ } }, "summary": "", - "tags": [ - "Campaign" - ], + "tags": ["Campaign"], "parameters": [ { "name": "id", @@ -2362,9 +2308,7 @@ } }, "summary": "", - "tags": [ - "Campaign" - ], + "tags": ["Campaign"], "requestBody": { "description": "", "required": true, @@ -2436,9 +2380,7 @@ } }, "summary": "", - "tags": [ - "Campaign" - ], + "tags": ["Campaign"], "parameters": [ { "name": "id", @@ -2503,9 +2445,7 @@ } }, "summary": "", - "tags": [ - "City" - ], + "tags": ["City"], "parameters": [ { "name": "_limit", @@ -2691,9 +2631,7 @@ } }, "summary": "", - "tags": [ - "City" - ], + "tags": ["City"], "requestBody": { "description": "", "required": true, @@ -2758,9 +2696,7 @@ } }, "summary": "", - "tags": [ - "City" - ], + "tags": ["City"], "parameters": [] } }, @@ -2811,9 +2747,7 @@ } }, "summary": "", - "tags": [ - "City" - ], + "tags": ["City"], "parameters": [ { "name": "id", @@ -2873,9 +2807,7 @@ } }, "summary": "", - "tags": [ - "City" - ], + "tags": ["City"], "requestBody": { "description": "", "required": true, @@ -2947,9 +2879,7 @@ } }, "summary": "", - "tags": [ - "City" - ], + "tags": ["City"], "parameters": [ { "name": "id", @@ -3014,9 +2944,7 @@ } }, "summary": "", - "tags": [ - "Contact" - ], + "tags": ["Contact"], "parameters": [ { "name": "_limit", @@ -3202,9 +3130,7 @@ } }, "summary": "", - "tags": [ - "Contact" - ], + "tags": ["Contact"], "requestBody": { "description": "", "required": true, @@ -3269,9 +3195,7 @@ } }, "summary": "", - "tags": [ - "Contact" - ], + "tags": ["Contact"], "parameters": [] } }, @@ -3322,9 +3246,7 @@ } }, "summary": "", - "tags": [ - "Contact" - ], + "tags": ["Contact"], "parameters": [ { "name": "id", @@ -3384,9 +3306,7 @@ } }, "summary": "", - "tags": [ - "Contact" - ], + "tags": ["Contact"], "requestBody": { "description": "", "required": true, @@ -3458,9 +3378,7 @@ } }, "summary": "", - "tags": [ - "Contact" - ], + "tags": ["Contact"], "parameters": [ { "name": "id", @@ -3525,9 +3443,7 @@ } }, "summary": "", - "tags": [ - "Disponibility" - ], + "tags": ["Disponibility"], "parameters": [ { "name": "_limit", @@ -3713,9 +3629,7 @@ } }, "summary": "", - "tags": [ - "Disponibility" - ], + "tags": ["Disponibility"], "requestBody": { "description": "", "required": true, @@ -3780,9 +3694,7 @@ } }, "summary": "", - "tags": [ - "Disponibility" - ], + "tags": ["Disponibility"], "parameters": [] } }, @@ -3833,9 +3745,7 @@ } }, "summary": "", - "tags": [ - "Disponibility" - ], + "tags": ["Disponibility"], "parameters": [ { "name": "id", @@ -3895,9 +3805,7 @@ } }, "summary": "", - "tags": [ - "Disponibility" - ], + "tags": ["Disponibility"], "requestBody": { "description": "", "required": true, @@ -3968,9 +3876,7 @@ } }, "summary": "", - "tags": [ - "Disponibility" - ], + "tags": ["Disponibility"], "parameters": [ { "name": "id", @@ -4035,9 +3941,7 @@ } }, "summary": "", - "tags": [ - "Disponibility" - ], + "tags": ["Disponibility"], "requestBody": { "description": "", "required": true, @@ -4097,9 +4001,7 @@ } }, "summary": "Confirm Campaign", - "tags": [ - "Disponibility" - ], + "tags": ["Disponibility"], "requestBody": { "description": "", "required": true, @@ -4183,9 +4085,7 @@ } }, "summary": "", - "tags": [ - "Dispositif" - ], + "tags": ["Dispositif"], "parameters": [ { "name": "_limit", @@ -4371,9 +4271,7 @@ } }, "summary": "", - "tags": [ - "Dispositif" - ], + "tags": ["Dispositif"], "requestBody": { "description": "", "required": true, @@ -4438,9 +4336,7 @@ } }, "summary": "", - "tags": [ - "Dispositif" - ], + "tags": ["Dispositif"], "parameters": [] } }, @@ -4491,9 +4387,7 @@ } }, "summary": "", - "tags": [ - "Dispositif" - ], + "tags": ["Dispositif"], "parameters": [ { "name": "id", @@ -4553,9 +4447,7 @@ } }, "summary": "", - "tags": [ - "Dispositif" - ], + "tags": ["Dispositif"], "requestBody": { "description": "", "required": true, @@ -4627,9 +4519,7 @@ } }, "summary": "", - "tags": [ - "Dispositif" - ], + "tags": ["Dispositif"], "parameters": [ { "name": "id", @@ -4694,9 +4584,7 @@ } }, "summary": "", - "tags": [ - "Espace" - ], + "tags": ["Espace"], "parameters": [ { "name": "_limit", @@ -4888,9 +4776,7 @@ } }, "summary": "", - "tags": [ - "Espace" - ], + "tags": ["Espace"], "parameters": [ { "name": "_limit", @@ -5076,9 +4962,7 @@ } }, "summary": "", - "tags": [ - "Espace" - ], + "tags": ["Espace"], "requestBody": { "description": "", "required": true, @@ -5143,9 +5027,7 @@ } }, "summary": "", - "tags": [ - "Espace" - ], + "tags": ["Espace"], "parameters": [ { "name": "_limit", @@ -5333,9 +5215,7 @@ } }, "summary": "", - "tags": [ - "Espace" - ], + "tags": ["Espace"], "parameters": [ { "name": "id", @@ -5405,9 +5285,7 @@ } }, "summary": "", - "tags": [ - "Espace" - ], + "tags": ["Espace"], "requestBody": { "description": "", "required": true, @@ -5479,9 +5357,7 @@ } }, "summary": "", - "tags": [ - "Espace" - ], + "tags": ["Espace"], "parameters": [ { "name": "id", @@ -5546,9 +5422,7 @@ } }, "summary": "", - "tags": [ - "Faq-category" - ], + "tags": ["Faq-category"], "parameters": [ { "name": "_limit", @@ -5738,9 +5612,7 @@ } }, "summary": "", - "tags": [ - "Faq-category" - ], + "tags": ["Faq-category"], "requestBody": { "description": "", "required": true, @@ -5805,9 +5677,7 @@ } }, "summary": "", - "tags": [ - "Faq-category" - ], + "tags": ["Faq-category"], "parameters": [] } }, @@ -5862,9 +5732,7 @@ } }, "summary": "", - "tags": [ - "Faq-category" - ], + "tags": ["Faq-category"], "parameters": [ { "name": "id", @@ -5928,9 +5796,7 @@ } }, "summary": "", - "tags": [ - "Faq-category" - ], + "tags": ["Faq-category"], "requestBody": { "description": "", "required": true, @@ -6002,9 +5868,7 @@ } }, "summary": "", - "tags": [ - "Faq-category" - ], + "tags": ["Faq-category"], "parameters": [ { "name": "id", @@ -6070,9 +5934,7 @@ } }, "summary": "", - "tags": [ - "Faq-question" - ], + "tags": ["Faq-question"], "parameters": [ { "name": "_limit", @@ -6262,9 +6124,7 @@ } }, "summary": "", - "tags": [ - "Faq-question" - ], + "tags": ["Faq-question"], "requestBody": { "description": "", "required": true, @@ -6329,9 +6189,7 @@ } }, "summary": "", - "tags": [ - "Faq-question" - ], + "tags": ["Faq-question"], "parameters": [] } }, @@ -6386,9 +6244,7 @@ } }, "summary": "", - "tags": [ - "Faq-question" - ], + "tags": ["Faq-question"], "parameters": [ { "name": "id", @@ -6452,9 +6308,7 @@ } }, "summary": "", - "tags": [ - "Faq-question" - ], + "tags": ["Faq-question"], "requestBody": { "description": "", "required": true, @@ -6526,9 +6380,7 @@ } }, "summary": "", - "tags": [ - "Faq-question" - ], + "tags": ["Faq-question"], "parameters": [ { "name": "id", @@ -6590,9 +6442,7 @@ } }, "summary": "", - "tags": [ - "Home-carousel" - ], + "tags": ["Home-carousel"], "parameters": [ { "name": "_limit", @@ -6782,9 +6632,7 @@ } }, "summary": "", - "tags": [ - "Home-carousel" - ], + "tags": ["Home-carousel"], "requestBody": { "description": "", "required": true, @@ -6845,9 +6693,7 @@ } }, "summary": "", - "tags": [ - "Home-carousel" - ], + "tags": ["Home-carousel"], "parameters": [] } }, @@ -6898,9 +6744,7 @@ } }, "summary": "", - "tags": [ - "Home-message" - ], + "tags": ["Home-message"], "parameters": [ { "name": "_limit", @@ -7091,9 +6935,7 @@ } }, "summary": "", - "tags": [ - "Home-message" - ], + "tags": ["Home-message"], "requestBody": { "description": "", "required": true, @@ -7154,9 +6996,7 @@ } }, "summary": "", - "tags": [ - "Home-message" - ], + "tags": ["Home-message"], "parameters": [] } }, @@ -7210,9 +7050,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "parameters": [] } }, @@ -7267,9 +7105,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "requestBody": { "description": "", "required": true, @@ -7331,9 +7167,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "parameters": [ { "name": "id", @@ -7398,9 +7232,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "parameters": [ { "name": "id", @@ -7601,9 +7433,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "parameters": [ { "name": "_limit", @@ -7789,9 +7619,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "requestBody": { "description": "", "required": true, @@ -7856,9 +7684,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "parameters": [] } }, @@ -7909,9 +7735,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "parameters": [ { "name": "id", @@ -7971,9 +7795,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "requestBody": { "description": "", "required": true, @@ -8045,9 +7867,7 @@ } }, "summary": "", - "tags": [ - "Message" - ], + "tags": ["Message"], "parameters": [ { "name": "id", @@ -8112,9 +7932,7 @@ } }, "summary": "", - "tags": [ - "Page" - ], + "tags": ["Page"], "parameters": [ { "name": "_limit", @@ -8300,9 +8118,7 @@ } }, "summary": "", - "tags": [ - "Page" - ], + "tags": ["Page"], "requestBody": { "description": "", "required": true, @@ -8367,9 +8183,7 @@ } }, "summary": "", - "tags": [ - "Page" - ], + "tags": ["Page"], "parameters": [] } }, @@ -8420,9 +8234,7 @@ } }, "summary": "", - "tags": [ - "Page" - ], + "tags": ["Page"], "parameters": [ { "name": "url", @@ -8484,9 +8296,7 @@ } }, "summary": "", - "tags": [ - "Page" - ], + "tags": ["Page"], "requestBody": { "description": "", "required": true, @@ -8558,9 +8368,7 @@ } }, "summary": "", - "tags": [ - "Page" - ], + "tags": ["Page"], "parameters": [ { "name": "id", @@ -8626,9 +8434,7 @@ } }, "summary": "", - "tags": [ - "Email - Email" - ], + "tags": ["Email - Email"], "requestBody": { "description": "", "required": true, @@ -8697,9 +8503,7 @@ } }, "summary": "", - "tags": [ - "Email - Email" - ], + "tags": ["Email - Email"], "requestBody": { "description": "", "required": true, @@ -8768,9 +8572,7 @@ } }, "summary": "", - "tags": [ - "Email - Email" - ], + "tags": ["Email - Email"], "parameters": [] } }, @@ -8858,9 +8660,7 @@ } }, "summary": "", - "tags": [ - "Upload - File" - ], + "tags": ["Upload - File"], "requestBody": { "description": "", "required": true, @@ -8925,9 +8725,7 @@ } }, "summary": "", - "tags": [ - "Upload - File" - ], + "tags": ["Upload - File"], "parameters": [] } }, @@ -8981,9 +8779,7 @@ } }, "summary": "", - "tags": [ - "Upload - File" - ], + "tags": ["Upload - File"], "parameters": [] } }, @@ -9034,9 +8830,7 @@ } }, "summary": "", - "tags": [ - "Upload - File" - ], + "tags": ["Upload - File"], "parameters": [ { "name": "id", @@ -9096,9 +8890,7 @@ } }, "summary": "", - "tags": [ - "Upload - File" - ], + "tags": ["Upload - File"], "parameters": [ { "name": "id", @@ -9163,9 +8955,7 @@ } }, "summary": "", - "tags": [ - "Upload - File" - ], + "tags": ["Upload - File"], "parameters": [ { "name": "id", @@ -9227,9 +9017,7 @@ } }, "summary": "", - "tags": [ - "Unclassified" - ], + "tags": ["Unclassified"], "parameters": [], "requestBody": { "description": "", @@ -9289,9 +9077,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - User" - ], + "tags": ["UsersPermissions - User"], "parameters": [] } }, @@ -9342,9 +9128,7 @@ } }, "summary": "", - "tags": [ - "Unclassified" - ], + "tags": ["Unclassified"], "requestBody": { "description": "", "required": true, @@ -9409,9 +9193,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - Role" - ], + "tags": ["UsersPermissions - Role"], "parameters": [ { "name": "id", @@ -9476,9 +9258,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - Role" - ], + "tags": ["UsersPermissions - Role"], "parameters": [ { "name": "_limit", @@ -9664,9 +9444,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - Role" - ], + "tags": ["UsersPermissions - Role"], "requestBody": { "description": "", "required": true, @@ -9727,9 +9505,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - Role" - ], + "tags": ["UsersPermissions - Role"], "parameters": [ { "name": "role", @@ -9804,9 +9580,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - Role" - ], + "tags": ["UsersPermissions - Role"], "parameters": [ { "name": "role", @@ -9871,9 +9645,7 @@ } }, "summary": "Retrieve a list of users by searching for their username or email", - "tags": [ - "UsersPermissions - User" - ], + "tags": ["UsersPermissions - User"], "parameters": [ { "name": "id", @@ -9928,9 +9700,7 @@ } }, "summary": "Authenticate your user with a custom provider", - "tags": [ - "Authentication" - ], + "tags": ["Authentication"], "parameters": [ { "name": "provider", @@ -9997,19 +9767,14 @@ } }, "summary": "", - "tags": [ - "Authentication" - ], + "tags": ["Authentication"], "requestBody": { "description": "The identifier param can either be an email or a username", "required": true, "content": { "application/json": { "schema": { - "required": [ - "identifier", - "password" - ], + "required": ["identifier", "password"], "properties": { "identifier": { "type": "string" @@ -10081,20 +9846,14 @@ } }, "summary": "", - "tags": [ - "Authentication" - ], + "tags": ["Authentication"], "requestBody": { "description": "", "required": true, "content": { "application/json": { "schema": { - "required": [ - "username", - "email", - "password" - ], + "required": ["username", "email", "password"], "properties": { "username": { "type": "string", @@ -10168,9 +9927,7 @@ } }, "summary": "", - "tags": [ - "Authentication" - ], + "tags": ["Authentication"], "parameters": [ { "name": "provider", @@ -10229,9 +9986,7 @@ } }, "summary": "Send an email to reset your password", - "tags": [ - "Authentication" - ], + "tags": ["Authentication"], "requestBody": { "description": "", "required": true, @@ -10309,20 +10064,14 @@ } }, "summary": "", - "tags": [ - "Authentication" - ], + "tags": ["Authentication"], "requestBody": { "description": "", "required": true, "content": { "application/json": { "schema": { - "required": [ - "code", - "password", - "passwordConfirmation" - ], + "required": ["code", "password", "passwordConfirmation"], "properties": { "code": { "type": "string" @@ -10393,9 +10142,7 @@ } }, "summary": "", - "tags": [ - "Authentication" - ], + "tags": ["Authentication"], "parameters": [ { "name": "confirmation", @@ -10461,18 +10208,14 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - User" - ], + "tags": ["UsersPermissions - User"], "requestBody": { "description": "", "required": true, "content": { "application/json": { "schema": { - "required": [ - "email" - ], + "required": ["email"], "properties": { "email": { "type": "string", @@ -10540,9 +10283,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - User" - ], + "tags": ["UsersPermissions - User"], "parameters": [ { "name": "_limit", @@ -10730,9 +10471,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - User" - ], + "tags": ["UsersPermissions - User"], "parameters": [ { "name": "id", @@ -10792,9 +10531,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - User" - ], + "tags": ["UsersPermissions - User"], "parameters": [ { "name": "id", @@ -10869,9 +10606,7 @@ } }, "summary": "", - "tags": [ - "UsersPermissions - User" - ], + "tags": ["UsersPermissions - User"], "parameters": [ { "name": "id", @@ -10890,12 +10625,7 @@ "components": { "schemas": { "Actuality": { - "required": [ - "id", - "title", - "content", - "image" - ], + "required": ["id", "title", "content", "image"], "properties": { "id": { "type": "string" @@ -10986,10 +10716,7 @@ } }, "NewActuality": { - "required": [ - "title", - "content" - ], + "required": ["title", "content"], "properties": { "title": { "type": "string" @@ -11013,32 +10740,20 @@ } }, "Application": { - "required": [ - "id" - ], + "required": ["id"], "properties": { "id": { "type": "string" }, "disponibility": { - "required": [ - "id", - "start", - "end", - "type", - "status" - ], + "required": ["id", "start", "end", "type", "status"], "properties": { "id": { "type": "string" }, "when": { "type": "string", - "enum": [ - "morning", - "afternoon", - "full" - ] + "enum": ["morning", "afternoon", "full"] }, "start": { "type": "string" @@ -11051,11 +10766,7 @@ }, "type": { "type": "string", - "enum": [ - "punctual", - "day", - "period" - ] + "enum": ["punctual", "day", "period"] }, "status": { "type": "string", @@ -11425,10 +11136,7 @@ }, "type": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "external_id": { "type": "integer" @@ -11578,11 +11286,7 @@ }, "danceCarpet": { "type": "string", - "enum": [ - "true", - "false", - "possible" - ] + "enum": ["true", "false", "possible"] }, "slug": { "type": "string" @@ -11621,10 +11325,7 @@ }, "status": { "type": "string", - "enum": [ - "preselected", - "confirmed" - ] + "enum": ["preselected", "confirmed"] }, "published_at": { "type": "string", @@ -11678,10 +11379,7 @@ }, "status": { "type": "string", - "enum": [ - "preselected", - "confirmed" - ] + "enum": ["preselected", "confirmed"] }, "published_at": { "type": "string", @@ -11696,9 +11394,7 @@ } }, "Booking": { - "required": [ - "id" - ], + "required": ["id"], "properties": { "id": { "type": "string" @@ -11835,24 +11531,14 @@ "disponibilities": { "type": "array", "items": { - "required": [ - "id", - "start", - "end", - "type", - "status" - ], + "required": ["id", "start", "end", "type", "status"], "properties": { "id": { "type": "string" }, "when": { "type": "string", - "enum": [ - "morning", - "afternoon", - "full" - ] + "enum": ["morning", "afternoon", "full"] }, "start": { "type": "string" @@ -11865,11 +11551,7 @@ }, "type": { "type": "string", - "enum": [ - "punctual", - "day", - "period" - ] + "enum": ["punctual", "day", "period"] }, "status": { "type": "string", @@ -12057,10 +11739,7 @@ }, "type": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "external_id": { "type": "integer" @@ -12113,9 +11792,7 @@ "applications": { "type": "array", "items": { - "required": [ - "id" - ], + "required": ["id"], "properties": { "id": { "type": "string" @@ -12170,10 +11847,7 @@ }, "status": { "type": "string", - "enum": [ - "preselected", - "confirmed" - ] + "enum": ["preselected", "confirmed"] }, "published_at": { "type": "string" @@ -12307,11 +11981,7 @@ } }, "City": { - "required": [ - "id", - "name", - "country" - ], + "required": ["id", "name", "country"], "properties": { "id": { "type": "string" @@ -12434,11 +12104,7 @@ }, "danceCarpet": { "type": "string", - "enum": [ - "true", - "false", - "possible" - ] + "enum": ["true", "false", "possible"] }, "slug": { "type": "string" @@ -12488,10 +12154,7 @@ } }, "NewCity": { - "required": [ - "name", - "country" - ], + "required": ["name", "country"], "properties": { "name": { "type": "string" @@ -12520,12 +12183,7 @@ } }, "Contact": { - "required": [ - "id", - "name", - "message", - "from" - ], + "required": ["id", "name", "message", "from"], "properties": { "id": { "type": "string" @@ -12542,11 +12200,7 @@ } }, "NewContact": { - "required": [ - "name", - "message", - "from" - ], + "required": ["name", "message", "from"], "properties": { "name": { "type": "string" @@ -12566,24 +12220,14 @@ } }, "Disponibility": { - "required": [ - "id", - "start", - "end", - "type", - "status" - ], + "required": ["id", "start", "end", "type", "status"], "properties": { "id": { "type": "string" }, "when": { "type": "string", - "enum": [ - "morning", - "afternoon", - "full" - ] + "enum": ["morning", "afternoon", "full"] }, "start": { "type": "string", @@ -12706,11 +12350,7 @@ }, "danceCarpet": { "type": "string", - "enum": [ - "true", - "false", - "possible" - ] + "enum": ["true", "false", "possible"] }, "slug": { "type": "string" @@ -12749,11 +12389,7 @@ }, "type": { "type": "string", - "enum": [ - "punctual", - "day", - "period" - ] + "enum": ["punctual", "day", "period"] }, "status": { "type": "string", @@ -12768,9 +12404,7 @@ ] }, "booking": { - "required": [ - "id" - ], + "required": ["id"], "properties": { "id": { "type": "string" @@ -12818,10 +12452,7 @@ } }, "dispositif": { - "required": [ - "id", - "name" - ], + "required": ["id", "name"], "properties": { "id": { "type": "string" @@ -12862,10 +12493,7 @@ } }, "message": { - "required": [ - "id", - "status" - ], + "required": ["id", "status"], "properties": { "id": { "type": "string" @@ -12881,10 +12509,7 @@ }, "author": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "status": { "type": "string", @@ -13029,9 +12654,7 @@ "applications": { "type": "array", "items": { - "required": [ - "id" - ], + "required": ["id"], "properties": { "id": { "type": "string" @@ -13086,10 +12709,7 @@ }, "status": { "type": "string", - "enum": [ - "preselected", - "confirmed" - ] + "enum": ["preselected", "confirmed"] }, "published_at": { "type": "string" @@ -13122,20 +12742,11 @@ } }, "NewDisponibility": { - "required": [ - "start", - "end", - "type", - "status" - ], + "required": ["start", "end", "type", "status"], "properties": { "when": { "type": "string", - "enum": [ - "morning", - "afternoon", - "full" - ] + "enum": ["morning", "afternoon", "full"] }, "start": { "type": "string", @@ -13150,11 +12761,7 @@ }, "type": { "type": "string", - "enum": [ - "punctual", - "day", - "period" - ] + "enum": ["punctual", "day", "period"] }, "status": { "type": "string", @@ -13211,10 +12818,7 @@ } }, "Dispositif": { - "required": [ - "id", - "name" - ], + "required": ["id", "name"], "properties": { "id": { "type": "string" @@ -13225,24 +12829,14 @@ "disponibilities": { "type": "array", "items": { - "required": [ - "id", - "start", - "end", - "type", - "status" - ], + "required": ["id", "start", "end", "type", "status"], "properties": { "id": { "type": "string" }, "when": { "type": "string", - "enum": [ - "morning", - "afternoon", - "full" - ] + "enum": ["morning", "afternoon", "full"] }, "start": { "type": "string" @@ -13255,11 +12849,7 @@ }, "type": { "type": "string", - "enum": [ - "punctual", - "day", - "period" - ] + "enum": ["punctual", "day", "period"] }, "status": { "type": "string", @@ -13438,10 +13028,7 @@ }, "type": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "external_id": { "type": "integer" @@ -13595,10 +13182,7 @@ }, "type": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "external_id": { "type": "integer" @@ -13639,9 +13223,7 @@ } }, "NewDispositif": { - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -13732,11 +13314,7 @@ }, "floor": { "type": "string", - "enum": [ - "plancherDanse", - "parquetTraditionnel", - "other" - ] + "enum": ["plancherDanse", "parquetTraditionnel", "other"] }, "otherFloor": { "type": "string" @@ -13802,11 +13380,7 @@ }, "danceCarpet": { "type": "string", - "enum": [ - "true", - "false", - "possible" - ] + "enum": ["true", "false", "possible"] }, "campaign_files": { "type": "array", @@ -13979,11 +13553,7 @@ }, "danceCarpet": { "type": "string", - "enum": [ - "true", - "false", - "possible" - ] + "enum": ["true", "false", "possible"] }, "slug": { "type": "string" @@ -14016,10 +13586,7 @@ } }, "Faq-category": { - "required": [ - "id", - "name" - ], + "required": ["id", "name"], "properties": { "id": { "type": "string" @@ -14030,11 +13597,7 @@ "faq_questions": { "type": "array", "items": { - "required": [ - "id", - "question", - "answer" - ], + "required": ["id", "question", "answer"], "properties": { "id": { "type": "string" @@ -14060,9 +13623,7 @@ } }, "NewFaq-category": { - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string" @@ -14082,11 +13643,7 @@ } }, "Faq-question": { - "required": [ - "id", - "question", - "answer" - ], + "required": ["id", "question", "answer"], "properties": { "id": { "type": "string" @@ -14098,10 +13655,7 @@ "type": "string" }, "faq_category": { - "required": [ - "id", - "name" - ], + "required": ["id", "name"], "properties": { "id": { "type": "string" @@ -14126,10 +13680,7 @@ } }, "NewFaq-question": { - "required": [ - "question", - "answer" - ], + "required": ["question", "answer"], "properties": { "question": { "type": "string" @@ -14149,10 +13700,7 @@ } }, "Home-carousel": { - "required": [ - "id", - "images" - ], + "required": ["id", "images"], "properties": { "id": { "type": "string" @@ -14240,10 +13788,7 @@ } }, "Home-message": { - "required": [ - "id", - "text" - ], + "required": ["id", "text"], "properties": { "id": { "type": "string" @@ -14261,9 +13806,7 @@ } }, "NewHome-message": { - "required": [ - "text" - ], + "required": ["text"], "properties": { "text": { "type": "string" @@ -14284,10 +13827,7 @@ } }, "Message": { - "required": [ - "id", - "status" - ], + "required": ["id", "status"], "properties": { "id": { "type": "string" @@ -14327,17 +13867,12 @@ }, "author": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] } } }, "NewMessage": { - "required": [ - "status" - ], + "required": ["status"], "properties": { "message": { "type": "string" @@ -14350,10 +13885,7 @@ }, "author": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "status": { "type": "string", @@ -14396,9 +13928,7 @@ } }, "ReadNotif": { - "required": [ - "status" - ], + "required": ["status"], "properties": { "bookingId": { "type": "string" @@ -14408,11 +13938,7 @@ }, "status": { "type": "string", - "enum": [ - "message", - "request", - "booking" - ] + "enum": ["message", "request", "booking"] } } }, @@ -14430,10 +13956,7 @@ } }, "Page": { - "required": [ - "id", - "url" - ], + "required": ["id", "url"], "properties": { "id": { "type": "string" @@ -14451,9 +13974,7 @@ } }, "NewPage": { - "required": [ - "url" - ], + "required": ["url"], "properties": { "title": { "type": "string" @@ -14520,10 +14041,7 @@ } }, "UsersPermissionsRole": { - "required": [ - "id", - "name" - ], + "required": ["id", "name"], "properties": { "id": { "type": "string" @@ -14541,13 +14059,7 @@ "permissions": { "type": "array", "items": { - "required": [ - "id", - "type", - "controller", - "action", - "enabled" - ], + "required": ["id", "type", "controller", "action", "enabled"], "properties": { "id": { "type": "string" @@ -14695,10 +14207,7 @@ }, "type": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "external_id": { "type": "integer" @@ -14739,9 +14248,7 @@ } }, "NewUsersPermissionsRole": { - "required": [ - "name" - ], + "required": ["name"], "properties": { "name": { "type": "string", @@ -14800,10 +14307,7 @@ "type": "string" }, "role": { - "required": [ - "id", - "name" - ], + "required": ["id", "name"], "properties": { "id": { "type": "string" @@ -14915,10 +14419,7 @@ }, "type": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "external_id": { "type": "string" @@ -15053,10 +14554,7 @@ }, "type": { "type": "string", - "enum": [ - "company", - "place" - ] + "enum": ["company", "place"] }, "created_by": { "type": "string" @@ -15067,10 +14565,7 @@ } }, "Error": { - "required": [ - "code", - "message" - ], + "required": ["code", "message"], "properties": { "code": { "type": "integer", @@ -15137,4 +14632,4 @@ "name": "UsersPermissions - User" } ] -} \ No newline at end of file +} diff --git a/web/components/Account/Application/Company/ApplicationCompanyList.tsx b/web/components/Account/Application/Company/ApplicationCompanyList.tsx index b7b983c..a857f87 100644 --- a/web/components/Account/Application/Company/ApplicationCompanyList.tsx +++ b/web/components/Account/Application/Company/ApplicationCompanyList.tsx @@ -6,6 +6,7 @@ import { Box, Divider as ChakraDivider, DividerProps, + useDisclosure, } from '@chakra-ui/react' import { useTranslation } from 'next-i18next' import { Application } from '~typings/api' @@ -14,6 +15,11 @@ import Cell from '~components/Account/Booking/Cell' import ApplicationCompanyListItem from '~components/Account/Application/Company/ApplicationCompanyListItem' import useCampaignContext from '~components/Campaign/useCampaignContext' import ApplicationCompanyHelper from '~components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper' +import ApplicationEditDrawer from '~components/Account/Application/Company/ApplicationEditDrawer' +import useToast from '~hooks/useToast' +import { client } from '~api/client-api' +import { useQueryClient } from 'react-query' +import { useRouter } from 'next/router' interface Props { applications: Application[] @@ -28,6 +34,9 @@ const ApplicationCompanyList = ({ applications = [] }: Props) => { const { t } = useTranslation('application') const [list, setList] = useState([]) const [isDesc, setDesc] = useState(true) + const { isOpen, onOpen, onClose } = useDisclosure() + const [selectedApplication, setSelectedApplication] = useState() + const { query } = useRouter() useEffect(() => { setList(applications) @@ -39,6 +48,21 @@ const ApplicationCompanyList = ({ applications = [] }: Props) => { setList(list.reverse()) } + const { successToast, errorToast } = useToast() + const queryClient = useQueryClient() + const handleDelete = async (applicationId) => { + try { + await client.applications.applicationsDelete(applicationId) + successToast(t('company.delete_success')) + queryClient.refetchQueries([ + 'myApplications', + query?.disponibility as string, + ]) + } catch (e) { + errorToast(t('company.delete_error')) + } + } + return ( { { + setSelectedApplication(application) + onOpen() + }} + handleDelete={() => handleDelete(application?.id)} /> ))} + { + handleDelete(selectedApplication?.id) + }} + /> ) } diff --git a/web/components/Account/Application/Company/ApplicationCompanyListItem.tsx b/web/components/Account/Application/Company/ApplicationCompanyListItem.tsx index db4cf8b..c6dd5d9 100644 --- a/web/components/Account/Application/Company/ApplicationCompanyListItem.tsx +++ b/web/components/Account/Application/Company/ApplicationCompanyListItem.tsx @@ -1,39 +1,25 @@ import React, { Fragment } from 'react' import { format } from '~utils/date' import { Application } from '~typings/api' -import { Text, Button } from '@chakra-ui/react' +import { Text, Button, ButtonGroup } from '@chakra-ui/react' import { useTranslation } from 'next-i18next' import Cell from '~components/Account/Booking/Cell' import ConfirmButton from '~components/Account/Application/ConfirmButton' -import { client } from '~api/client-api' -import useToast from '~hooks/useToast' -import { useQueryClient } from 'react-query' import useCampaignContext from '~components/Campaign/useCampaignContext' -import { useRouter } from 'next/router' interface Props { application: Application + onSelect: () => void + handleDelete: () => void } -const ApplicationCompanyListItem = ({ application }: Props) => { +const ApplicationCompanyListItem = ({ + application, + onSelect, + handleDelete, +}: Props) => { const { currentCampaign } = useCampaignContext() - const { errorToast, successToast } = useToast() const { t } = useTranslation('application') - const queryClient = useQueryClient() - const { query } = useRouter() - - const onDelete = async () => { - try { - await client.applications.applicationsDelete(application.id) - successToast(t('company.delete_success')) - queryClient.refetchQueries([ - 'myApplications', - query?.disponibility as string, - ]) - } catch (e) { - errorToast(t('company.delete_error')) - } - } return ( @@ -68,11 +54,7 @@ const ApplicationCompanyListItem = ({ application }: Props) => { {currentCampaign?.mode === 'applications' && ( - + - + + + + + )} diff --git a/web/components/Account/Application/Company/ApplicationEditDrawer.tsx b/web/components/Account/Application/Company/ApplicationEditDrawer.tsx new file mode 100644 index 0000000..f60988c --- /dev/null +++ b/web/components/Account/Application/Company/ApplicationEditDrawer.tsx @@ -0,0 +1,173 @@ +import { + Drawer, + DrawerCloseButton, + DrawerContent, + DrawerHeader, + DrawerOverlay, + VStack, + Divider, + Grid, + GridItem, + Box, +} from '@chakra-ui/react' +import { useTranslation } from 'next-i18next' +import ApplicationDetailHeader from '~components/Account/Application/Place/DetailDrawer/ApplicationDetailHeader' +import { Application } from '~typings/api' +import ApplicationEditRightPanel from '~components/Account/Application/Company/ApplicationEditRightPanel' +import { FormProvider, useForm } from 'react-hook-form' +import { + getApplicationDefaultValues, + getApplicationFormData, + getApplicationSchema, +} from '~components/Campaign/Places/Application/ApplicationForm' +import { yupResolver } from '@hookform/resolvers/yup' +import { useEffect, useState } from 'react' +import { useCurrentUser } from '~hooks/useCurrentUser' +import useCampaignContext from '~components/Campaign/useCampaignContext' +import useToast from '~hooks/useToast' +import ApplicationReferences from '~components/Campaign/Places/Application/References/ApplicationReferences' +import ApplicationGeneral from '~components/Campaign/Places/Application/ApplicationGeneral' +import ApplicationCreation from '~components/Campaign/Places/Application/ApplicationCreation' +import { client } from '~api/client-api' +import { useQueryClient } from 'react-query' +import { useRouter } from 'next/router' + +const ApplicationEditDrawer = ({ + isOpen, + onClose, + application, + handleDelete, +}: { + isOpen: boolean + onClose: () => void + application: Application + handleDelete: () => void +}) => { + const [isLoading, setIsLoading] = useState(false) + const { t } = useTranslation('application') + const { t: tPlace } = useTranslation('place') + const schema = getApplicationSchema(tPlace, true) + + const form = useForm({ + resolver: yupResolver(schema), + }) + + const { handleSubmit, reset } = form + const { id } = application ?? {} + const { data: user } = useCurrentUser() + const { currentCampaign } = useCampaignContext() + const { successToast, errorToast } = useToast() + const queryClient = useQueryClient() + const { query } = useRouter() + + useEffect(() => { + const defaultValues = getApplicationDefaultValues(application) + reset(defaultValues) + }, [application, reset]) + + const onSubmit = async (formValues) => { + setIsLoading(true) + + const applicationFileId = application?.creation_file?.[0]?.id + const formFileId = formValues?.creation_file?.[0]?.id + + const fileHasChanged = + (applicationFileId && !formFileId) || formFileId !== applicationFileId + const removedFileId = + fileHasChanged && applicationFileId ? applicationFileId : undefined + + // If file has changed and is not used by other applications delete old file from server + if (fileHasChanged) { + const { data } = await client.upload.filesDetail(removedFileId) + const isUsedByOtherApplications = data?.related?.length > 1 + if (!isUsedByOtherApplications) { + await client.upload.filesDelete(removedFileId) + } + } + + try { + const formData = getApplicationFormData({ + formValues, + user, + currentCampaign, + place: application.disponibility?.espace, + disponibilityId: application.disponibility.id, + }) + + //@ts-expect-error + await client.applications.applicationsUpdate(application.id, formData) + reset(getApplicationDefaultValues(formValues)) + successToast(t('company.detail.saved')) + queryClient.refetchQueries([ + 'myApplications', + query?.disponibility as string, + ]) + onClose() + } catch (e) { + console.log(e) + errorToast(t('company.detail.error_saved')) + } + setIsLoading(false) + } + + if (!application) { + return null + } + + return ( + + + + + + {t('place.detail.title', { id })} + + + +
+ + + + + + + + + + + + + + + + + + + + +
+
+
+
+ ) +} + +export default ApplicationEditDrawer diff --git a/web/components/Account/Application/Company/ApplicationEditRightPanel.tsx b/web/components/Account/Application/Company/ApplicationEditRightPanel.tsx new file mode 100644 index 0000000..e63ec11 --- /dev/null +++ b/web/components/Account/Application/Company/ApplicationEditRightPanel.tsx @@ -0,0 +1,139 @@ +import { VStack, Divider, Button, Text, HStack, Box } from '@chakra-ui/react' +import { useTranslation } from 'next-i18next' +import { Application } from '~typings/api' +import BackIcon from '~public/assets/icons/BackIcon' +import ForbiddenIcon from '~public/assets/icons/ForbiddenIcon' +import ValidateIcon from '~public/assets/icons/ValidateIcon' +import ConfirmButton from '~components/Account/Application/ConfirmButton' +import Link from '~components/Link' + +const ApplicationEditRightPanel = ({ + application, + isLoading, + handleBack, + handleDelete, + handleSubmit, +}: { + application: Application + isLoading?: boolean + handleBack: () => void + handleDelete: () => void + handleSubmit: () => void +}) => { + const { t } = useTranslation('application') + + const espace = application?.disponibility?.espace + // @ts-expect-error + const { email, phone, website } = espace?.users_permissions_user ?? {} + + return ( + + + + + + + + + + + + + + + {/* @ts-expect-error */} + {espace.name} + + + {t('place.detail.right_panel.phone')} + {phone} + + + + {t('place.detail.right_panel.email')} + {email} + + + + {website} + + + + + ) +} + +export default ApplicationEditRightPanel diff --git a/web/components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper.tsx b/web/components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper.tsx index 153f9e3..1d61c9e 100644 --- a/web/components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper.tsx +++ b/web/components/Account/Application/Company/ApplicationsHelpers/ApplicationCompanyHelper.tsx @@ -11,7 +11,7 @@ const ApplicationCompanyHelper = () => { const today = new Date() if ( - applications.length > 0 && + applications?.length > 0 && !remainingApplications && currentCampaign.mode === 'applications' ) { diff --git a/web/components/Account/Application/Place/DetailDrawer/ApplicationDetailHeader.tsx b/web/components/Account/Application/Place/DetailDrawer/ApplicationDetailHeader.tsx index ef22229..45d3d5d 100644 --- a/web/components/Account/Application/Place/DetailDrawer/ApplicationDetailHeader.tsx +++ b/web/components/Account/Application/Place/DetailDrawer/ApplicationDetailHeader.tsx @@ -5,8 +5,10 @@ import { format } from '~utils/date' const ApplicationDetailHeader = ({ application, + isCompany, }: { application: Application + isCompany?: boolean }) => { const { t } = useTranslation('application') @@ -36,13 +38,27 @@ const ApplicationDetailHeader = ({ - {t('place.detail.header.company')} - {application?.company?.structureName} + {isCompany ? ( + <> + {t('place.detail.header.place')} + + { + // @ts-expect-error + application?.disponibility?.espace?.users_permissions_user + ?.structureName + } + + + ) : ( + <> + {t('place.detail.header.company')} + {application?.company?.structureName} + + )} ) diff --git a/web/components/Campaign/Places/Application/ApplicationCreation.tsx b/web/components/Campaign/Places/Application/ApplicationCreation.tsx index 39f2213..82d5b3f 100644 --- a/web/components/Campaign/Places/Application/ApplicationCreation.tsx +++ b/web/components/Campaign/Places/Application/ApplicationCreation.tsx @@ -5,7 +5,7 @@ import FileField from '~components/Campaign/Places/Application/Inputs/FileField' import TextAreaField from '~components/Campaign/Places/Application/Inputs/TextAreaField' import TextField from '~components/Campaign/Places/Application/Inputs/TextField' -const ApplicationCreation = () => { +const ApplicationCreation = (isUpdate: { isUpdate?: boolean }) => { const { t } = useTranslation('place') return ( diff --git a/web/components/Campaign/Places/Application/ApplicationForm.tsx b/web/components/Campaign/Places/Application/ApplicationForm.tsx index 077c8fd..a623280 100644 --- a/web/components/Campaign/Places/Application/ApplicationForm.tsx +++ b/web/components/Campaign/Places/Application/ApplicationForm.tsx @@ -15,25 +15,85 @@ import { useCurrentUser } from '~hooks/useCurrentUser' import ApplicationReferences from '~components/Campaign/Places/Application/References/ApplicationReferences' import { Espace } from '~typings/api' -const getDefaultValues = (applications) => { - if (applications?.length > 0) { - const lastApplication = applications[applications?.length - 1] +export const getApplicationFormData = ({ + formValues, + user, + currentCampaign, + place, + disponibilityId, +}) => { + const { form, data } = Object.keys(formValues).reduce( + (total, key) => { + if (key === 'creation_file') { + if (formValues[key].length > 0) { + Array.from(formValues[key]).map((file: any, index) => + total.form.append( + `files.creation_file`, + file?.caption + ? new File([file], file.caption, { type: file.type }) + : file, + ), + ) + } else { + total.data[`creation_file`] = [] + } + } else if (key === 'references') { + total.data[key] = JSON.stringify(formValues[key]) + } else { + total.data[key] = formValues[key] + } + return total + }, + { + form: new FormData(), + data: { + company: user.id, + espace: place.id, + disponibility: disponibilityId, + campaign: currentCampaign?.id, + }, + }, + ) + form.append('data', JSON.stringify(data)) + return form +} + +export const getApplicationDefaultValues = (application) => { + if (application) { const data = { - ...lastApplication, + ...application, references: - lastApplication?.references?.map((el) => ({ + application?.references?.map((el) => ({ ...el, - coproducers: Array.isArray(el.coproducers) - ? el.coproducers - : el.coproducers.split(',').map((el) => +el), + coproducers: Array.isArray(el?.coproducers) + ? el?.coproducers + : el?.coproducers?.split(',').map((el) => +el), })) || [], - already_supported: lastApplication?.already_supported.toString(), + already_supported: application?.already_supported.toString(), } return data } return {} } + +export const getApplicationSchema = (t, isUpdate = false) => + yup.object().shape({ + already_supported: yup.boolean().required(t('global.required')), + cv: yup.string().required(t('global.required')), + creation_title: yup.string().required(t('global.required')), + creation_dancers: yup.number().required(t('global.required')), + // creation_file: yup + // .array() + // .min(1, t('global.required')) + // .required(t('global.required')), + creation_summary: yup.string().required(t('global.required')), + creation_techical_requirements: yup.string().required(t('global.required')), + eligibility: isUpdate + ? yup.boolean() + : yup.boolean().required(t('global.required')), + }) + const ApplicationForm = ({ back, setConfirmed, @@ -47,27 +107,16 @@ const ApplicationForm = ({ }) => { const { applications } = useCurrentUser() const { t } = useTranslation('place') - const schema = yup.object().shape({ - already_supported: yup.boolean().required(t('global.required')), - cv: yup.string().required(t('global.required')), - creation_title: yup.string().required(t('global.required')), - creation_dancers: yup.number().required(t('global.required')), - // creation_file: yup - // .array() - // .min(1, t('global.required')) - // .required(t('global.required')), - creation_summary: yup.string().required(t('global.required')), - creation_techical_requirements: yup.string().required(t('global.required')), - eligibility: yup.boolean().required(t('global.required')), - }) + const schema = getApplicationSchema(t) const { data: user } = useCurrentUser() const { currentCampaign } = useCampaignContext() - + const lastApplication = applications[applications?.length - 1] const form = useForm({ resolver: yupResolver(schema), - defaultValues: getDefaultValues(applications), + defaultValues: getApplicationDefaultValues(lastApplication), }) + const { errorToast } = useToast() const [isLoading, setLoading] = useState(false) const { handleSubmit } = form @@ -77,36 +126,13 @@ const ApplicationForm = ({ try { await Promise.all( events.map(async (event) => { - const { form, data } = Object.keys(formValues).reduce( - (total, key) => { - if (key === 'creation_file') { - Array.from(formValues[key]).map((file: any, index) => - total.form.append( - `files.creation_file`, - file?.caption - ? new File([file], file.caption, { type: file.type }) - : file, - ), - ) - } else if (key === 'references') { - total.data[key] = JSON.stringify(formValues[key]) - } else { - total.data[key] = formValues[key] - } - return total - }, - { - form: new FormData(), - data: { - company: user.id, - espace: place.id, - disponibility: event?.extendedProps?.id, - campaign: currentCampaign?.id, - }, - }, - ) - - form.append('data', JSON.stringify(data)) + const form = getApplicationFormData({ + formValues, + user, + currentCampaign, + place, + disponibilityId: event?.extendedProps?.id, + }) //@ts-expect-error await client.applications.applicationsCreate(form) }), diff --git a/web/components/Campaign/Places/Application/Inputs/FileField.tsx b/web/components/Campaign/Places/Application/Inputs/FileField.tsx index f575595..78baa68 100644 --- a/web/components/Campaign/Places/Application/Inputs/FileField.tsx +++ b/web/components/Campaign/Places/Application/Inputs/FileField.tsx @@ -123,7 +123,11 @@ const FileInput = ({ {file?.name} - {(file?.size / (1000 * 1000)).toFixed(1)}mo + {(file?.id + ? file.size / 1000 + : file?.size / (1000 * 1000) + ).toFixed(1)} + mo diff --git a/web/components/Campaign/Places/Application/References/ApplicationReferences.tsx b/web/components/Campaign/Places/Application/References/ApplicationReferences.tsx index 0a93578..f1fe77f 100644 --- a/web/components/Campaign/Places/Application/References/ApplicationReferences.tsx +++ b/web/components/Campaign/Places/Application/References/ApplicationReferences.tsx @@ -32,7 +32,7 @@ const ApplicationReferences = () => { <> {REFERENCE_FIELDS.map((field) => ( = requireAuth( async ({ locale }) => { return { props: { - ...(await serverSideTranslations(locale, ['account', 'application'])), + ...(await serverSideTranslations(locale, [ + 'account', + 'application', + 'place', + ])), }, } }, diff --git a/web/public/assets/icons/BackIcon.tsx b/web/public/assets/icons/BackIcon.tsx new file mode 100644 index 0000000..dbf0ffb --- /dev/null +++ b/web/public/assets/icons/BackIcon.tsx @@ -0,0 +1,55 @@ +const BackIcon = ({ stroke }) => ( + + + + + + + + + + + + + + + +) + +export default BackIcon diff --git a/web/public/assets/icons/ForbiddenIcon.tsx b/web/public/assets/icons/ForbiddenIcon.tsx new file mode 100644 index 0000000..c3d5648 --- /dev/null +++ b/web/public/assets/icons/ForbiddenIcon.tsx @@ -0,0 +1,23 @@ +const ForbiddenIcon = ({ stroke }) => ( + + + + +) + +export default ForbiddenIcon diff --git a/web/public/assets/icons/ValidateIcon.tsx b/web/public/assets/icons/ValidateIcon.tsx new file mode 100644 index 0000000..248e3f4 --- /dev/null +++ b/web/public/assets/icons/ValidateIcon.tsx @@ -0,0 +1,31 @@ +const ValidateIcon = ({ stroke }) => ( + + + + + + + + + + + +) + +export default ValidateIcon diff --git a/web/public/locales/fr/application.json b/web/public/locales/fr/application.json index a2b9e20..077f55d 100644 --- a/web/public/locales/fr/application.json +++ b/web/public/locales/fr/application.json @@ -11,6 +11,7 @@ "creation": "Création" }, "delete": "Supprimer", + "edit": "Modifier", "cancel": "Annuler", "delete_helper": "Être sûr de vouloir supprimer cette candidature ?" }, @@ -26,7 +27,15 @@ "full_end": "La décision de chaque lieu sera connue d’ici au {{date}}. En cas de sélection, le lieu prendra contact directement avec vous par email. Merci pour votre participation." }, "delete_error": "Une erreur est survenue lors de la suppression de votre candidature", - "delete_success": "Votre candidature a bien été supprimée" + "delete_success": "Votre candidature a bien été supprimée", + "detail": { + "back": "Retour", + "cancel": "Annuler cette candidature", + "save": "Enregistrer les modifications", + "saving": "Enregistrement en cours", + "saved": "Vos modifications ont bien été enregistrées", + "error_saved": "Une erreur est survenue lors de l'enregistrement de vos modifications" + } }, "place": { "title": "Candidatures – ", @@ -64,7 +73,8 @@ "header": { "slot": "Créneau", "space": "Espace", - "company": "Compagnie" + "company": "Compagnie", + "place": "Lieu" }, "right_panel": { "phone": "Tél :", diff --git a/web/public/locales/fr/place.json b/web/public/locales/fr/place.json index 137c875..95f9685 100644 --- a/web/public/locales/fr/place.json +++ b/web/public/locales/fr/place.json @@ -2,7 +2,8 @@ "global": { "file": { "change": "Changer", - "file-too-large": "Le fichier est trop volumineux" + "file-too-large": "Le fichier est trop volumineux", + "delete_error": "Une erreur est survenue lors de la suppression de votre fichier" }, "yes": "Oui", "no": "Non",