Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving my stuff over #8

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions server/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ NODE_ENV=${NODE_ENV:-production}
# done


version="0.0.0"
version="0.0.1"
commit="abc123"
date="13-08-2023"
author="Ivan D Gomez J"
date="04-11-2024"
author="NineMinds"

# Function to print colored text
print_color() {
Expand All @@ -27,8 +27,8 @@ print_color() {

# Print the first ASCII art
print_color "35" "
*******
****************
*******
****************
***********************
*****************************
*********************************
Expand Down Expand Up @@ -69,14 +69,13 @@ print_color "35" "

# Print the second ASCII art
print_color "34" "
###### ######## ######## ### ###### ######## #### ### ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ### ##
## ## ## ## ## ## ## ## ## ## ## #### ##
###### ###### ######## ## ## ###### ## ## ## ## ## ## ##
## ## ## ## ######### ## ## ## ######### ## ####
## ## ## ## ## ## ## ## ## ## ## ## ## ## ###
###### ######## ######## ## ## ###### ## #### ## ## ## ##

### ## ###### ### ###### ##### ###
## ## ## ## ## ## ## # # # # ## ##
## ## ## ## ## ## # # # ## ##
## ## ## ## #### ## ## ###### ##### ## ##
######### ## ## ## ######### # # #########
## ## ## ## ## ## ## # # ## ##
## ## ######## ###### ## ## # ##### ## ##


##### ####### ###### # # ####### ######
Expand All @@ -92,12 +91,12 @@ print_color "34" "
print_color "36" "
****************************************************
* *
* SEBASTIAN NEXT.JS *
* ALGA PSA NEXT.JS *
* *
* Version .: $version *
* Commit .: $commit *
* Date .: $date *
* Author .: $author *
* Version .: $version *
* Commit .: $commit *
* Date .: $date *
* Author .: $author *
* *
****************************************************
"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exports.up = async function(knex) {
await knex.schema.alterTable('contacts', (table) => {
table.text('notes');
});

await knex.schema.alterTable('companies', (table) => {
table.text('notes');
});
};

exports.down = async function(knex) {
await knex.schema.alterTable('contacts', (table) => {
table.dropColumn('notes');
});

await knex.schema.alterTable('companies', (table) => {
table.dropColumn('notes');
});
};
2 changes: 2 additions & 0 deletions server/src/components/companies/Companies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const Companies: React.FC = () => {
address: data.address || '',
is_inactive: data.is_inactive || false,
is_tax_exempt: data.is_tax_exempt || false,
notes: data.notes,
client_type: data.client_type || 'company',
tenant: data.tenant!
};
await createCompany(newCompanyData);
Expand Down
43 changes: 38 additions & 5 deletions server/src/components/companies/CompanyDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import { ArrowLeft } from 'lucide-react';
import { getCurrentUser } from '@/lib/actions/user-actions/userActions';
import { IUserWithRoles } from '@/interfaces/auth.interfaces';
import { useRouter, usePathname } from 'next/navigation';
import { TextArea } from '@/components/ui/TextArea';

interface CompanyDetailsProps {
company: ICompany;
documents?: IDocument[];
contacts?: IContact[];
isInDrawer?: boolean; // Prop to indicate if component is rendered in a drawer
isInDrawer?: boolean;
}

const TextDetailItem: React.FC<{
Expand Down Expand Up @@ -58,6 +59,38 @@ const TextDetailItem: React.FC<{
);
};

const NotesDetailItem: React.FC<{
value: string;
onEdit: (value: string) => void;
onSave: () => void;
}> = ({ value, onEdit, onSave }) => {
const [localValue, setLocalValue] = useState(value);

const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setLocalValue(e.target.value);
onEdit(e.target.value);
};

return (
<div className="space-y-4">
<Text as="label" size="2" className="text-gray-700 font-medium">Notes</Text>
<TextArea
value={localValue}
onChange={handleChange}
placeholder="Add notes about this company..."
/>
<div className="flex justify-end">
<Button
onClick={onSave}
className="bg-blue-600 text-white hover:bg-blue-700 transition-colors"
>
Save Notes
</Button>
</div>
</div>
);
};

const SwitchDetailItem: React.FC<{
value: boolean;
onEdit: (value: boolean) => void;
Expand Down Expand Up @@ -332,10 +365,10 @@ const CompanyDetails: React.FC<CompanyDetailsProps> = ({
{
label: "Notes",
content: (
<TextDetailItem
label="Notes"
value={editedCompany.properties?.notes ?? ""}
onEdit={(value) => handleFieldChange('properties.notes', value)}
<NotesDetailItem
value={editedCompany.notes ?? ""}
onEdit={(value) => handleFieldChange('notes', value)}
onSave={handleSave}
/>
)
},
Expand Down
207 changes: 138 additions & 69 deletions server/src/components/companies/CompanyForm.tsx
Original file line number Diff line number Diff line change
@@ -1,96 +1,165 @@
// server/src/components/CompanyForm.tsx
import React from 'react';
import { useForm } from 'react-hook-form';
import React, { useState } from 'react';
import { ICompany } from '@/interfaces/company.interfaces';
import { Input } from "@/components/ui/Input";
import { Button } from "@/components/ui/Button";
import { Label } from "@/components/ui/Label";
import { Select } from "@/components/ui/Select";
import { TextArea } from "@/components/ui/TextArea";

interface CompanyFormProps {
onSubmit: (data: Omit<ICompany, "company_id" | "created_at" | "updated_at">) => void;
}

const CompanyForm: React.FC<CompanyFormProps> = ({ onSubmit }) => {
const { register, handleSubmit, setValue, formState: { errors } } = useForm<Omit<ICompany, "company_id" | "created_at" | "updated_at">>();
const [formData, setFormData] = useState({
company_name: '',
client_type: 'company',
phone_no: '',
email: '',
url: '',
address: '',
notes: '',
is_inactive: false,
is_tax_exempt: false,
properties: {
industry: '',
company_size: '',
annual_revenue: ''
}
});

const clientTypeOptions = [
{ value: 'company', label: 'Company' },
{ value: 'individual', label: 'Individual' }
];
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
onSubmit(formData);
};

const handleChange = (field: string, value: string | boolean) => {
if (field.startsWith('properties.')) {
const propertyField = field.split('.')[1];
setFormData(prev => ({
...prev,
properties: {
...prev.properties,
[propertyField]: value
}
}));
} else {
setFormData(prev => ({
...prev,
[field]: value
}));
}
};

return (
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div>
<Label htmlFor="company_name">Company Name</Label>
<Input
id="company_name"
{...register('company_name', { required: 'Company name is required' })}
/>
{errors.company_name && <p className="mt-1 text-sm text-red-600">{errors.company_name.message}</p>}
</div>
<form onSubmit={handleSubmit} className="flex flex-col h-[600px]">
<div className="flex-1 overflow-hidden">
<div className="h-full overflow-y-auto px-4 space-y-4 pb-4">
<div>
<Label htmlFor="company_name">Company Name</Label>
<Input
id="company_name"
value={formData.company_name}
onChange={(e) => handleChange('company_name', e.target.value)}
required
/>
</div>

<div>
<Select
id="client_type"
label="Client Type"
options={clientTypeOptions}
onChange={(value) => setValue('client_type', value)}
/>
{errors.client_type && <p className="mt-1 text-sm text-red-600">{errors.client_type.message}</p>}
</div>
<div>
<Select
id="client_type"
label="Client Type"
options={[
{ value: 'company', label: 'Company' },
{ value: 'individual', label: 'Individual' }
]}
value={formData.client_type}
onChange={(value) => handleChange('client_type', value)}
/>
</div>

<div>
<Label htmlFor="phone_no">Phone Number</Label>
<Input
id="phone_no"
{...register('phone_no')}
/>
</div>
<div>
<Label htmlFor="phone_no">Phone Number</Label>
<Input
id="phone_no"
value={formData.phone_no}
onChange={(e) => handleChange('phone_no', e.target.value)}
/>
</div>

<div>
<Label htmlFor="url">URL</Label>
<Input
id="url"
{...register('url')}
/>
</div>
<div>
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
value={formData.email}
onChange={(e) => handleChange('email', e.target.value)}
/>
</div>

<div>
<Label htmlFor="address">Address</Label>
<Input
id="address"
{...register('address')}
/>
</div>
<div>
<Label htmlFor="url">URL</Label>
<Input
id="url"
value={formData.url}
onChange={(e) => handleChange('url', e.target.value)}
/>
</div>

<div>
<Label htmlFor="industry">Industry</Label>
<Input
id="industry"
{...register('properties.industry')}
/>
</div>
<div>
<Label htmlFor="address">Address</Label>
<Input
id="address"
value={formData.address}
onChange={(e) => handleChange('address', e.target.value)}
/>
</div>

<div>
<Label htmlFor="company_size">Company Size</Label>
<Input
id="company_size"
{...register('properties.company_size')}
/>
</div>
<div>
<Label htmlFor="industry">Industry</Label>
<Input
id="industry"
value={formData.properties.industry}
onChange={(e) => handleChange('properties.industry', e.target.value)}
/>
</div>

<div>
<Label htmlFor="company_size">Company Size</Label>
<Input
id="company_size"
value={formData.properties.company_size}
onChange={(e) => handleChange('properties.company_size', e.target.value)}
/>
</div>

<div>
<Label htmlFor="annual_revenue">Annual Revenue</Label>
<Input
id="annual_revenue"
{...register('properties.annual_revenue')}
/>
<div>
<Label htmlFor="annual_revenue">Annual Revenue</Label>
<Input
id="annual_revenue"
value={formData.properties.annual_revenue}
onChange={(e) => handleChange('properties.annual_revenue', e.target.value)}
/>
</div>

<div>
<Label htmlFor="notes">Notes</Label>
<TextArea
id="notes"
value={formData.notes}
onChange={(e) => handleChange('notes', e.target.value)}
placeholder="Add any additional notes"
/>
</div>
</div>
</div>

<Button type="submit">
Create Client
</Button>
<div className="pt-4 mt-4 border-t">
<Button type="submit">
Create Client
</Button>
</div>
</form>
);
};
Expand Down
Loading
Loading