Skip to content
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
9 changes: 9 additions & 0 deletions docs/supabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ yarn generate:seed
```

Each time

## Types

You can generate the types from the database with the command :
```
yarn types:generate
```

This script use Supabase CLI to generate the types file from your local database. You just need to go remove the last line inside the file `src/shared/types/supabase.ts` after running the command.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"check": "biome check .",
"preview": "vite preview",
"seed:sync": "npx @snaplet/seed sync",
"seed:generate": "npx --yes tsx supabase/seeds/seed.ts > supabase/seeds/default.sql"
"seed:generate": "npx --yes tsx supabase/seeds/seed.ts > supabase/seeds/default.sql",
"types:generate": "supabase gen types typescript --local > src/shared/types/supabase.ts"
},
"dependencies": {
"@ant-design/icons": "5.x",
Expand Down Expand Up @@ -43,7 +44,7 @@
"@vitejs/plugin-react": "^4.5.2",
"bcryptjs": "^3.0.2",
"postgres": "^3.4.7",
"supabase": "^2.31.8",
"supabase": "^2.34.3",
"typescript": "~5.8.3",
"vite": "^7.0.0"
},
Expand Down
6 changes: 4 additions & 2 deletions public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@
"serial_number": "Serial Number",
"warranty_end_date": "Warranty End Date",
"purchase_value": "Purchase Value",
"purchase_date": "Purchase Date"
"purchase_date": "Purchase Date",
"quantity": "Quantity"
},
"validation": {
"name_required": "Equipment name is required.",
"system_required": "System is required."
"system_required": "System is required.",
"quantity_required": "Quantity is required (minimum 1)."
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@
"serial_number": "Numéro de série",
"warranty_end_date": "Fin de garantie",
"purchase_value": "Valeur d'achat",
"purchase_date": "Date d'achat"
"purchase_date": "Date d'achat",
"quantity": "Quantité"
},
"validation": {
"name_required": "Le nom de l'équipement est requis.",
"system_required": "Le système est requis."
"system_required": "Le système est requis.",
"quantity_required": "La quantité est requise (minimum 1)."
}
}
},
Expand Down
14 changes: 14 additions & 0 deletions src/equipments/components/equipment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ const EquipmentForm: FC<EquipmentFormProps> = ({
>
<InputNumber style={{ width: '100%' }} min={0} step={0.01} suffix="€" />
</Form.Item>
<Form.Item
label={translate('equipments.form.labels.quantity')}
name="quantity"
rules={[
{
required: true,
type: 'number',
min: 1,
message: translate('equipments.form.validation.quantity_required'),
},
]}
>
<InputNumber style={{ width: '100%' }} min={1} step={1} />
</Form.Item>
</Form>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/equipments/pages/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const EquipmentList = () => {
<Link
to={`/boats/${boat?.data.id}/equipments/${equipment.id}`}
>
{equipment.quantity > 1
? `${equipment.quantity} x `
: null}
{equipment.name}
</Link>
}
Expand Down
24 changes: 20 additions & 4 deletions src/equipments/pages/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const ShowEquipment = () => {
<Card>
<Typography.Paragraph>
<strong>{translate('equipments.form.labels.name')}: </strong>
{equipment?.data.quantity > 1
? `${equipment?.data.quantity} x `
: null}
{equipment?.data.name}
</Typography.Paragraph>
<Typography.Paragraph>
Expand Down Expand Up @@ -66,10 +69,23 @@ const ShowEquipment = () => {
<strong>
{translate('equipments.form.labels.purchase_value')}:{' '}
</strong>
{equipment.data.purchase_value.toLocaleString(undefined, {
style: 'currency',
currency: 'EUR',
})}
{equipment?.data.quantity > 1
Comment thread
cballevre marked this conversation as resolved.
? `${equipment.data.quantity} x ${equipment.data.purchase_value.toLocaleString(
undefined,
{
style: 'currency',
currency: 'EUR',
},
)} = ${(
equipment.data.quantity * equipment.data.purchase_value
Comment thread
cballevre marked this conversation as resolved.
).toLocaleString(undefined, {
style: 'currency',
currency: 'EUR',
})}`
: equipment.data.purchase_value.toLocaleString(undefined, {
style: 'currency',
currency: 'EUR',
})}
</Typography.Paragraph>
) : null}
{equipment?.data.purchase_date ? (
Expand Down
93 changes: 88 additions & 5 deletions src/shared/types/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,30 @@ export type Json =
| Json[];

export type Database = {
// Allows to automatically instanciate createClient with right options
// instead of createClient<Database, { PostgrestVersion: 'XX' }>(URL, KEY)
__InternalSupabase: {
PostgrestVersion: '12.2.12 (cd3cf9e)';
graphql_public: {
Tables: {
[_ in never]: never;
};
Views: {
[_ in never]: never;
};
Functions: {
graphql: {
Args: {
operationName?: string;
query?: string;
variables?: Json;
extensions?: Json;
};
Returns: Json;
};
};
Enums: {
[_ in never]: never;
};
CompositeTypes: {
[_ in never]: never;
};
};
public: {
Tables: {
Expand Down Expand Up @@ -75,6 +95,7 @@ export type Database = {
file_path: string;
file_type: string | null;
id: string;
type: string;
uploaded_at: string;
};
Insert: {
Expand All @@ -84,6 +105,7 @@ export type Database = {
file_path: string;
file_type?: string | null;
id?: string;
type?: string;
uploaded_at?: string;
};
Update: {
Expand All @@ -93,11 +115,12 @@ export type Database = {
file_path?: string;
file_type?: string | null;
id?: string;
type?: string;
uploaded_at?: string;
};
Relationships: [
{
foreignKeyName: 'attachments_equipment_id_fkey';
foreignKeyName: 'equipment_attachments_equipment_id_fkey';
columns: ['equipment_id'];
isOneToOne: false;
referencedRelation: 'equipments';
Expand All @@ -116,6 +139,7 @@ export type Database = {
name: string;
purchase_date: string | null;
purchase_value: number | null;
quantity: number;
serial_number: string | null;
system_key: string;
warranty_end_date: string | null;
Expand All @@ -130,6 +154,7 @@ export type Database = {
name: string;
purchase_date?: string | null;
purchase_value?: number | null;
quantity?: number;
serial_number?: string | null;
system_key: string;
warranty_end_date?: string | null;
Expand All @@ -144,6 +169,7 @@ export type Database = {
name?: string;
purchase_date?: string | null;
purchase_value?: number | null;
quantity?: number;
serial_number?: string | null;
system_key?: string;
warranty_end_date?: string | null;
Expand All @@ -158,30 +184,80 @@ export type Database = {
},
];
};
intervention_attachments: {
Row: {
description: string | null;
file_name: string;
file_path: string;
file_type: string | null;
id: string;
intervention_id: string;
type: string;
uploaded_at: string;
};
Insert: {
description?: string | null;
file_name: string;
file_path: string;
file_type?: string | null;
id?: string;
intervention_id: string;
type?: string;
uploaded_at?: string;
};
Update: {
description?: string | null;
file_name?: string;
file_path?: string;
file_type?: string | null;
id?: string;
intervention_id?: string;
type?: string;
uploaded_at?: string;
};
Relationships: [
{
foreignKeyName: 'intervention_attachments_intervention_id_fkey';
columns: ['intervention_id'];
isOneToOne: false;
referencedRelation: 'interventions';
referencedColumns: ['id'];
},
];
};
interventions: {
Row: {
boat_id: string;
created_at: string;
date: string;
description: string | null;
id: string;
labor_cost: number | null;
supply_cost: number | null;
title: string;
total_cost: number | null;
};
Insert: {
boat_id: string;
created_at?: string;
date: string;
description?: string | null;
id?: string;
labor_cost?: number | null;
supply_cost?: number | null;
title: string;
total_cost?: number | null;
};
Update: {
boat_id?: string;
created_at?: string;
date?: string;
description?: string | null;
id?: string;
labor_cost?: number | null;
supply_cost?: number | null;
title?: string;
total_cost?: number | null;
};
Relationships: [
{
Expand All @@ -202,6 +278,10 @@ export type Database = {
Args: { equipment_id: string };
Returns: boolean;
};
check_intervention_access: {
Args: { intervention_id: string };
Returns: boolean;
};
has_boat_access: {
Args: { boat: string };
Returns: boolean;
Expand Down Expand Up @@ -337,6 +417,9 @@ export type CompositeTypes<
: never;

export const Constants = {
graphql_public: {
Enums: {},
},
public: {
Enums: {
access_role: ['owner', 'operator', 'viewer'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table "public"."equipments" add column "quantity" integer not null default 1;


1 change: 1 addition & 0 deletions supabase/schemas/equipments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ create table public.equipments (
warranty_end_date timestamp with time zone,
purchase_value real,
purchase_date timestamp with time zone,
quantity integer not null default 1,
created_at timestamp with time zone not null default now(),
boat_id uuid not null,
system_key text not null,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6112,10 +6112,10 @@ sunflower-antd@1.0.0-beta.3:
resolved "https://registry.yarnpkg.com/sunflower-antd/-/sunflower-antd-1.0.0-beta.3.tgz#5e72feefc8f592f4eda6cbc7bd7f9421463c6980"
integrity sha512-SAdjHgNemTFNxUF/QJ2KdC0x6wWpY1EsMJMo+F5KIHCDRsUUahjAIldoK+ejH00rPgUoCOhAHQ/ob/J7eyZ5qg==

supabase@^2.31.8:
version "2.31.8"
resolved "https://registry.yarnpkg.com/supabase/-/supabase-2.31.8.tgz#a5058a42eaf5975014ef9b08ef75826f9cf9a4b7"
integrity sha512-AsALbB9qKqUhu5A8gZK5VMR2SPo2DPP7W544MBk7JKfLo3Pi8YoAxGxx5skarfeqDtHkzEREU/seFIaYP/bl3A==
supabase@^2.34.3:
version "2.34.3"
resolved "https://registry.yarnpkg.com/supabase/-/supabase-2.34.3.tgz#42c8f68d99f578fc16756e3229cf1794036eccc6"
integrity sha512-nMO7MFkw3ze/ScRt8S7AssNuBDbFeEsu2MTF2hol5T8HoAz5WgoLhhwCL5NUh8G0Jigpg88QIaDEPhHdNvv9TQ==
dependencies:
bin-links "^5.0.0"
https-proxy-agent "^7.0.2"
Expand Down