Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SethSharp committed Jan 31, 2024
1 parent f7919ed commit a3c07a6
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 59 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ module.exports = {
"react"
],
"rules": {
"semi": "off"
}
}
4 changes: 0 additions & 4 deletions app/Domain/Blog/Models/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class Blog extends Model
{
use HasFactory;

const STATUS_DRAFT = 'draft';
const STATUS_PUBLISHED = 'published';
const STATUS_DELETED = 'deleted';

public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'author_id');
Expand Down
5 changes: 4 additions & 1 deletion database/factories/Domain/Blog/Models/BlogFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ public function definition()

return [
'author_id' => User::factory()->create()->id,
'is_draft' => false,
'title' => $name,
'slug' => $slug,
'meta_title' => fake()->text(20),
'meta_description' => fake()->text(100),
'meta_tags' => fake()->text(10),
'content' => fake()->text(),
'status' => Blog::STATUS_DRAFT
];
}
}
6 changes: 3 additions & 3 deletions database/factories/Domain/Iam/Models/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function definition()
];
}

public function unverified()
public function unverified(): self
{
return $this->state(function (array $attributes) {
return [
Expand All @@ -35,7 +35,7 @@ public function admin(): self
{
return $this->afterCreating(function (User $user) {
$user->roles()->attach([
Role::whereName(User::ROLE_ADMIN)
Role::whereName(User::ROLE_ADMIN)->first()->id
]);
});
}
Expand All @@ -44,7 +44,7 @@ public function author(): self
{
return $this->afterCreating(function (User $user) {
$user->roles()->attach([
Role::whereName(User::ROLE_AUTHOR)
Role::whereName(User::ROLE_AUTHOR)->first()->id
]);
});
}
Expand Down
6 changes: 4 additions & 2 deletions database/migrations/2024_01_24_014509_create_blogs_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public function up()
$table->boolean('is_draft');
$table->string('title');
$table->string('slug');
$table->text('content');
$table->string('status');
$table->string('meta_title');
$table->string('meta_description');
$table->string('meta_tags');
$table->string('content');
$table->timestamps();
});
}
Expand Down
4 changes: 2 additions & 2 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function run()
$blog->tags()->syncWithoutDetaching([$tag1->id, $tag2->id]);

User::factory()->author()->create([
'name' => 'Admin',
'email' => 'admin@portfolio.test',
'name' => 'Author',
'email' => 'author@portfolio.test',
'password' => Hash::make('123456')
]);
}
Expand Down
18 changes: 17 additions & 1 deletion resources/js/Components/Form/Form.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import React from "react";

export default function Form({ children }) {
return <div className="w-3/4 p-8">{children}</div>;
const contentSlot = React.Children.toArray(children).filter(
(child) => child.props.slot === "content",
);

const actionsSlot = React.Children.toArray(children).filter(
(child) => child.props.slot === "actions",
);

return (
<div className="w-3/4 p-8">
<div className="">{contentSlot}</div>

<div className="mt-6">{actionsSlot}</div>
</div>
);
}
2 changes: 1 addition & 1 deletion resources/js/Components/PrimaryButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function PrimaryButton({
<button
{...props}
className={
`inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 focus:bg-gray-700 active:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition ease-in-out duration-150 ${
`inline-flex items-center px-4 py-2 bg-primary-500 border border-transparent rounded-md font-medium text-xs text-white tracking-widest hover:bg-primary-600 focus:bg-primary-700 active:bg-primary-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition ease-in-out duration-150 ${
disabled && "opacity-25"
} ` + className
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Components/SecondaryButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function SecondaryButton({
{...props}
type={type}
className={
`inline-flex items-center px-4 py-2 bg-white border border-gray-300 rounded-md font-semibold text-xs text-gray-700 uppercase tracking-widest shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:opacity-25 transition ease-in-out duration-150 ${
`inline-flex items-center px-4 py-2 bg-white border border-gray-300 rounded-md font-medium text-xs text-gray-700 tracking-widest shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:opacity-25 transition ease-in-out duration-150 ${
disabled && "opacity-25"
} ` + className
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Components/TextInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default forwardRef(function TextInput(
{...props}
type={type}
className={
"border-gray-300 p-2 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm " +
"border border-gray-300 p-2 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm " +
className
}
ref={input}
Expand Down
127 changes: 91 additions & 36 deletions resources/js/Pages/Dashboard/Blogs/Create.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import TextInput from "@/Components/TextInput.jsx";
import PrimaryButton from "@/Components/PrimaryButton.jsx";
import { Transition } from "@headlessui/react";
import Form from "@/Components/Form/Form.jsx";
import SecondaryButton from "@/Components/SecondaryButton.jsx";

export default function Index({ auth }) {
const { data, setData, post, processing, errors, reset } = useForm({
title: "",
slug: "",
meta_title: "",
meta_description: "",
meta_tags: "",
content: "",
});

Expand All @@ -24,47 +28,98 @@ export default function Index({ auth }) {
return (
<AuthenticatedLayout user={auth.user}>
<Head title="Blog" />
<div>
<form onSubmit={submit} className="w-3/4">
<Form>
<div slot="content">
<TextInput
id="title"
type="title"
name="title"
value={data.title}
className="mt-1 block w-full"
isFocused={true}
label="Title"
onChange={(e) =>
setData("title", e.target.value)
}
/>

<Form>
<form onSubmit={submit}>
<TextInput
id="title"
type="title"
name="title"
value={data.title}
className="mt-1 block w-full"
isFocused={true}
label="Title"
onChange={(e) => setData("title", e.target.value)}
/>
<TextInput
id="slug"
type="slug"
name="slug"
value={data.slug}
className="mt-1 block w-full"
label="Slug"
onChange={(e) =>
setData("slug", e.target.value)
}
/>

<TextInput
id="slug"
type="slug"
name="slug"
value={data.slug}
className="mt-1 block w-full"
label="Slug"
onChange={(e) => setData("slug", e.target.value)}
/>
<TextInput
id="meta_title"
type="meta_title"
name="meta_title"
value={data.meta_title}
className="mt-1 block w-full"
label="Meta Title"
onChange={(e) =>
setData("meta_title", e.target.value)
}
/>

<TextInput
id="content"
type="content"
name="content"
value={data.content}
className="mt-1 block w-full"
label="Content"
onChange={(e) => setData("content", e.target.value)}
/>
<TextInput
id="meta_description"
type="meta_description"
name="meta_description"
value={data.meta_description}
className="mt-1 block w-full"
label="Meta Description"
onChange={(e) =>
setData("meta_description", e.target.value)
}
/>

<div className="mt-6 justify-end">
<PrimaryButton disabled={processing}>
Save
</PrimaryButton>
</div>
<TextInput
id="meta_tags"
type="meta_tags"
name="meta_tags"
value={data.meta_tags}
className="mt-1 block w-full"
label="Meta Tags"
onChange={(e) =>
setData("meta_tags", e.target.value)
}
/>

<TextInput
id="content"
type="content"
name="content"
value={data.content}
className="mt-1 block w-full"
label="Content"
onChange={(e) =>
setData("content", e.target.value)
}
/>
</div>

<div slot="actions">
<div className="flex gap-x-2 flex-row-reverse">
<PrimaryButton disabled={processing}>
Save
</PrimaryButton>

<SecondaryButton disabled={processing}>
Save as Draft
</SecondaryButton>
</div>
</div>
</Form>
</form>
</Form>
</div>
</AuthenticatedLayout>
);
}
28 changes: 21 additions & 7 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
const defaultTheme = require('tailwindcss/defaultTheme');
const defaultTheme = require("tailwindcss/defaultTheme");
import colors from "tailwindcss/colors.js";

/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
'./resources/js/**/*.jsx',
"./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php",
"./storage/framework/views/*.php",
"./resources/views/**/*.blade.php",
"./resources/js/**/*.jsx",
],

theme: {
extend: {
fontFamily: {
sans: ['Figtree', ...defaultTheme.fontFamily.sans],
sans: ["Figtree", ...defaultTheme.fontFamily.sans],
},
colors: {
primary: {
100: colors.yellow[100],
200: colors.yellow[200],
300: colors.yellow[300],
400: colors.yellow[400],
500: colors.yellow[500],
600: colors.yellow[600],
700: colors.yellow[700],
800: colors.yellow[800],
900: colors.yellow[900],
},
},
},
},

plugins: [require('@tailwindcss/forms')],
plugins: [require("@tailwindcss/forms")],
};

0 comments on commit a3c07a6

Please sign in to comment.