diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index 741732b..dd760f2 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -8,7 +8,7 @@ use App\Models\Question; use App\Models\Response; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; - +use Illuminate\Support\Facades\Session; class FormController extends Controller { public function index() @@ -64,7 +64,7 @@ return view('forms.edit', compact('form', 'questions')); $question->save(); } - + Session::flash('success', 'Form created successfully!'); return response()->json(['success' => true, 'form_id' => $form->id]); } @@ -76,6 +76,12 @@ return view('forms.edit', compact('form', 'questions')); return view('forms.show', compact('form')); } + public function preview($id) +{ + $form = Form::findOrFail($id); + return view('forms.previewForm', compact('form')); +} + public function update(Request $request, Form $form) { @@ -147,6 +153,6 @@ return view('forms.edit', compact('form', 'questions')); // This will also delete all related questions and responses due to foreign key constraints $form->delete(); - return redirect()->route('forms.index')->with('success', 'Form deleted successfully.'); + return redirect()->route('forms.index')->with('delete', 'Form deleted successfully.'); } } diff --git a/app/Http/Controllers/ResponseController.php b/app/Http/Controllers/ResponseController.php index 032ea8c..85b0ae2 100644 --- a/app/Http/Controllers/ResponseController.php +++ b/app/Http/Controllers/ResponseController.php @@ -49,6 +49,9 @@ public function viewResponses(Form $form) public function showForm(Form $form) { $questions = $form->questions; + if (!$form->is_published) { + return redirect('/forms')->with('delete', 'This form is not published.'); + } return view('responses.showForm', compact('form', 'questions')); } diff --git a/package-lock.json b/package-lock.json index e67502b..d436571 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,9 @@ "requires": true, "packages": { "": { + "dependencies": { + "sweetalert": "^2.1.2" + }, "devDependencies": { "@popperjs/core": "^2.11.6", "axios": "^1.6.4", @@ -723,6 +726,11 @@ "node": ">=0.4.0" } }, + "node_modules/es6-object-assign": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", + "integrity": "sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw==" + }, "node_modules/esbuild": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz", @@ -994,6 +1002,11 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/promise-polyfill": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-6.1.0.tgz", + "integrity": "sha512-g0LWaH0gFsxovsU7R5LrrhHhWAWiHRnh1GPrhXnPgYsDkIqjRYUYSZEsej/wtleDrz5xVSIDbeKfidztp2XHFQ==" + }, "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -1073,6 +1086,15 @@ "node": ">=0.10.0" } }, + "node_modules/sweetalert": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/sweetalert/-/sweetalert-2.1.2.tgz", + "integrity": "sha512-iWx7X4anRBNDa/a+AdTmvAzQtkN1+s4j/JJRWlHpYE8Qimkohs8/XnFcWeYHH2lMA8LRCa5tj2d244If3S/hzA==", + "dependencies": { + "es6-object-assign": "^1.1.0", + "promise-polyfill": "^6.0.2" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", diff --git a/package.json b/package.json index 9a0b5bf..8e672e9 100644 --- a/package.json +++ b/package.json @@ -12,5 +12,8 @@ "laravel-vite-plugin": "^1.0.0", "sass": "^1.56.1", "vite": "^5.0.0" + }, + "dependencies": { + "sweetalert": "^2.1.2" } } diff --git a/public/css/app.css b/public/css/app.css index 6561243..860fa64 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -32,6 +32,7 @@ top: 0; left: 75%; top: 10%; + border-radius: 6px; } .btnp { diff --git a/public/css/index.css b/public/css/index.css index dec785d..364ba71 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -1,90 +1,104 @@ -body { - font-family: "Open Sans", sans-serif; - background-color: #f2f2f2; - margin: 0; - padding: 0; -} -.form_header { - display: flex; - justify-content: space-between; - align-items: center; - background-color: white; - color: white; - padding: 10px 20px; -} -.form_header_left { - display: flex; - align-items: center; -} -.form_header_icon { - margin-right: 10px; -} -.form_header_right { - display: flex; - align-items: center; -} -.form_header_right img { - margin-right: 10px; - cursor: pointer; -} -.container { - max-width: 800px; - margin: 20px auto; - background-color: white; - padding-top: 10px; - border-top: 12px rgb(103, 58, 183) solid; - border-left: 4px #4285f4 solid; - border-radius: 8px; - box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); -} -.start_form { - margin-bottom: 10px; - background-color: #f5f5f5; - padding: 10px; - border-radius: 8px; - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); -} -.start_form a { - text-decoration: none; - color: rgb(103, 58, 183); -} -.start_form a:hover { - text-decoration: underline; -} -.recent_forms { - background-color: #f4f4f9; - padding: 20px; - border-radius: 5px; - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); -} -.recent_forms h2 { - color: rgb(103, 58, 183); - margin-bottom: 10px; -} -.recent_forms ul { - list-style-type: none; - padding: 0; -} -.recent_forms ul li { - margin-bottom: 10px; -} -.recent_forms ul li a { - color: #333; - text-decoration: none; - display: block; - padding: 10px; - border-radius: 4px; - background-color: #e0e0e0; - transition: background-color 0.3s ease; -} -.recent_forms ul li a:hover { - background-color: #c5c5c5; -} -.form_name { - color: #5f6368; -} -.roboto-light { - font-family: "Roboto", sans-serif; - font-weight: 150; - font-style: normal; -} + body { + font-family: "Open Sans", sans-serif; + background-color: #f2f2f2; + margin: 0; + padding: 0; + } + .form_header { + display: flex; + justify-content: space-between; + align-items: center; + background-color: white; + color: white; + padding: 10px 20px; + } + .form_header_left { + display: flex; + align-items: center; + } + .form_header_icon { + margin-right: 10px; + } + .form_header_right { + display: flex; + align-items: center; + } + .form_header_right img { + margin-right: 10px; + cursor: pointer; + } + .container { + max-width: 800px; + margin: 20px auto; + background-color: white; + padding-top: 10px; + border-top: 12px rgb(103, 58, 183) solid; + border-left: 4px #4285f4 solid; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + } + .start_form { + margin-bottom: 10px; + background-color: #f5f5f5; + padding: 10px; + border-radius: 8px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + } + .start_form a { + text-decoration: none; + color: rgb(103, 58, 183); + } + .start_form a:hover { + text-decoration: underline; + } + .recent_forms { + background-color: #f4f4f9; + padding: 20px; + border-radius: 5px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + } + .recent_forms h2 { + color: rgb(103, 58, 183); + margin-bottom: 10px; + } + .recent_forms ul { + list-style-type: none; + padding: 0; + } + .recent_forms ul li { + margin-bottom: 10px; + } + .recent_forms ul li a { + color: #333; + text-decoration: none; + display: block; + padding: 10px; + border-radius: 4px; + background-color: #e0e0e0; + transition: background-color 0.3s ease; + } + .recent_forms ul li a:hover { + background-color: #c5c5c5; + } + .form_name { + color: black; + font-weight: 500; + } + .roboto-light { + font-family: "Roboto", sans-serif; + font-weight: 150; + font-style: normal; + } + + #shareLink{ + border: 2px solid black; + } + + .btn-primary{ + background-color: rgb(103, 58, 183); + } + + :hover.btn-primary{ + background-color: rgb(96, 4, 96); + color: white; + } diff --git a/public/css/preview.css b/public/css/preview.css new file mode 100644 index 0000000..cf1e516 --- /dev/null +++ b/public/css/preview.css @@ -0,0 +1,56 @@ +.form_preview { + padding: 20px; + max-width: 600px; + margin: auto; + background-color: #f4f4f9; + border-radius: 8px; +} + +#form_name { + font-family: Arial, Helvetica, sans-serif; + font-size: 32px; + font-weight: 400; + line-height: 135%; + border-bottom: 1px solid #f4f4f9; + color: black; +} + +#form_desc { + font-family: Arial, Helvetica, sans-serif; + font-size: 13px; + font-weight: 400; + line-height: 100%; + border-bottom: 1px solid #f4f4f9; + color: black; + margin-top: 10px; +} + + +.question { + margin-bottom: 20px; + background-color: #fff; + border-radius: 8px; + padding: 20px; + border-top: 8px solid rgb(103, 58, 183); +} + +.question_title { + font-weight: bold; + font-size: 18px; + margin-bottom: 10px; +} + +.options { + margin-top: 10px; +} + +.option { + margin-bottom: 10px; + display: flex; + align-items: center; +} + +.option input[type="radio"], +.option input[type="checkbox"] { + margin-right: 10px; +} diff --git a/public/js/script.js b/public/js/script.js index 5d8d24a..b91e120 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -48,7 +48,7 @@ document.addEventListener("DOMContentLoaded", function () { `; questionsSection.appendChild(newQuestionDiv); @@ -133,7 +133,7 @@ document.addEventListener("DOMContentLoaded", function () { window.changeQuestionType = changeQuestionType; window.saveForm = saveForm; - window.previewForm = function () { + window.previewForm = function (formId) { const formTitle = document.getElementById("form-title").value; const formDescription = document.getElementById("form-description").value; @@ -160,7 +160,7 @@ document.addEventListener("DOMContentLoaded", function () { data: JSON.stringify(formData), }); - window.open(`preview.html?${formParams.toString()}`, "_blank"); + window.location.href = '/forms/' + formId + '/preview'; }; window.addNewQuestion = addNewQuestion; diff --git a/resources/views/forms/create.blade.php b/resources/views/forms/create.blade.php index 8457e91..77f2f4e 100644 --- a/resources/views/forms/create.blade.php +++ b/resources/views/forms/create.blade.php @@ -27,7 +27,7 @@ pallette eye + onclick="previewForm()" /> @@ -54,7 +54,7 @@ -
+

@@ -92,14 +92,14 @@
-
+
- - + @if (session('success')) + + @endif + @if (session('delete')) + + @endif

Recent Forms

@@ -48,30 +65,41 @@ - - - - + + + + - @foreach($forms as $form) + @foreach ($forms as $form) - +
Form TitleCreated AtResponsesActions + Form Title + Created At + Responses + Actions
- {{ $form->title }} + {{ $form->title }}

{{ $form->description }}

{{ $form->created_at->format('M d, Y') }}{{ $form->created_at->format('M d, Y') }} + - @if ($form->is_published) - View Responses - @else - Not Published - @endif + View Responses - Edit - + @if (!$form->is_published) + Edit + @endif + @csrf @method('DELETE') @@ -89,13 +117,13 @@ document.getElementById('profileMenuButton').addEventListener('click', function() { document.getElementById('profileMenu').classList.toggle('hidden'); }); + setTimeout(function() { + var successMessage = document.getElementById('successMessage'); + if (successMessage) { + successMessage.remove(); + } + }, 3000); + - - - - - - - diff --git a/resources/views/forms/previewForm.blade.php b/resources/views/forms/previewForm.blade.php new file mode 100644 index 0000000..3e875f3 --- /dev/null +++ b/resources/views/forms/previewForm.blade.php @@ -0,0 +1,66 @@ + + + + + + + Form Preview + + + + + +
+

+

+
+
+ + + + diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 35404d8..478510d 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -17,9 +17,9 @@ @vite(['resources/sass/app.scss', 'resources/js/app.js']) - +
-