Skip to content

Commit

Permalink
Fix - Correction de null exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmugnier committed Jun 10, 2021
1 parent dfcee87 commit 163afc9
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/helpers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const unfreezeBody = () => {
window.scrollTo(0, parseInt(scrollY || "0") * -1);
};

export const formatMoney = (price) => `${price.toFixed(2).replace(".", ",")}€`;
export const formatMoney = (price) => (price ? `${price.toFixed(2).replace(".", ",")}€` : "");

export const isBio = (tags) => {
if (typeof tags === "string") return tags.indexOf("bio") > -1;
Expand Down
41 changes: 22 additions & 19 deletions src/routes/catalogs/AddProductModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
...$products,
...temp.map((r) => ({
...r,
addedOn: Date.now(),
addedOn: null,
})),
];
close();
Expand All @@ -44,38 +44,41 @@
...p,
checked: false,
}));
if (allProducts.length == 0) close();
},
error: () => close(),
errorNotification: "Impossible de récupérer les informations des produits",
});
});
$: hasSelectedAll = allProducts.filter((p) => !p.checked).length == 0;
</script>

<div class="pb-2">
<div class="flex justify-between bg-primary -mx-6 px-6 py-2 -mt-2 items-center md:rounded-t-l">
<h3 class="text-lg font-semibold text-white mb-0">Choisir des produits à ajouter</h3>
</div>
<div class="flex items-center cursor-pointer mt-3 mb-2" on:click={() => toggleAll()}>
<div class="w-1/12">
<InputCheckbox checked={hasSelectedAll} />
</div>
<p class>Tout sélectionner</p>
</div>
{#each allProducts as product}
<div
class="flex border-b border-gray-400 py-2 items-center cursor-pointer"
on:click={() => (product.checked = !product.checked)}
>
{#if allProducts.length > 0}
<div class="flex items-center cursor-pointer mt-3 mb-2" on:click={() => toggleAll()}>
<div class="w-1/12">
<InputCheckbox checked={product.checked} />
<InputCheckbox checked={hasSelectedAll} />
</div>
<p class:font-semibold={product.checked}>{product.name}</p>
<p class>Tout sélectionner</p>
</div>
{/each}
<button class="btn btn-accent btn-lg my-3 m-auto" type="button" on:click={handleSubmit}>Ajouter ces produits</button>
{#each allProducts as product}
<div
class="flex border-b border-gray-400 py-2 items-center cursor-pointer"
on:click={() => (product.checked = !product.checked)}
>
<div class="w-1/12">
<InputCheckbox checked={product.checked} />
</div>
<p class:font-semibold={product.checked}>{product.name}</p>
</div>
{/each}
<button class="btn btn-accent btn-lg my-3 m-auto" type="button" on:click={handleSubmit}>Ajouter ces produits</button
>
{:else}
<p class="my-3">Vous ne possédez pas de produits.</p>
<button class="btn btn-accent btn-lg my-3 m-auto" type="button" on:click={close}>Fermer</button>
{/if}
</div>
3 changes: 1 addition & 2 deletions src/routes/catalogs/CatalogForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
onDestroy(async () => {
await form.destroy();
});
</script>

<form class="w-full" on:submit|preventDefault={() => form.validateAndSubmit(submit)}>
Expand All @@ -36,7 +35,7 @@
disabled={$form.isSubmitting}
id="grid-product"
type="text"
placeholder="Catalogue petits magasins été"
placeholder="Catalogue GMS"
/>
</div>
<ErrorContainer field={$form.fields.name} />
Expand Down
13 changes: 7 additions & 6 deletions src/routes/catalogs/CatalogProducts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
errorsHandler;
const routerInstance = GetRouterInstance();
const { open, clearApolloCache } = getContext("modal");
const { open } = getContext("modal");
const { clearApolloCache } = getContext("api");
const headers = [
{ label: "Nom", mobile: true },
Expand Down Expand Up @@ -59,9 +60,7 @@
});
$: $products = catalog.products;
$: invalidCatalogProducts =
$products.length == 0 || ($products.length > 0 && $products.filter((p) => !p.wholeSalePricePerUnit).length);
$: invalidCatalogProducts = $products.length > 0 && $products.filter((p) => !p.wholeSalePricePerUnit).length;
</script>

<table class="shadow">
Expand Down Expand Up @@ -112,7 +111,9 @@
</td>
<td class="px-3 md:px-6 py-4 whitespace-no-wrap border-b border-gray-200 hidden lg:table-cell">
<div class="text-sm leading-5 font-medium truncate" style="max-width: 180px;">
{format(new Date(product.addedOn), "PP", { locale: fr })}
{product.addedOn
? format(new Date(product.addedOn), "PP", { locale: fr })
: format(new Date(), "PP", { locale: fr })}
</div>
</td>
<td class="px-3 md:px-6 py-4 whitespace-no-wrap border-b border-gray-200 hidden lg:table-cell">
Expand All @@ -137,7 +138,7 @@
Ajouter des produits
</button>
</td>
{#if catalog.id && catalog.id.length > 0}
{#if catalog.id && catalog.id.length > 0 && $products.length > 0 && $products.filter((p) => !p.addedOn).length < 1}
<td class="px-3 md:px-6 py-2 whitespace-no-wrap border-b border-gray-200">
<button type="button" class="flex items-center btn-link" on:click={showUpdateCatalogPricesModal}>
<Icon data={faEdit} class="mr-2" />
Expand Down
8 changes: 6 additions & 2 deletions src/routes/catalogs/EditCatalog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import PageHeader from "../../components/PageHeader.svelte";
import PageBody from "../../components/PageBody.svelte";
import { normalizeCatalog } from "./catalogForm";
import CatalogKind from "../../enums/CatalogKind";
export let params;
Expand Down Expand Up @@ -65,19 +66,22 @@
onClose: (res) => routerInstance.goTo(CatalogRoutes.Details, { id: res.id }),
});
const buttons = [
$: isConsumerCatalog = catalog && catalog.kind === CatalogKind.Consumers.Value;
$: buttons = [
{
text: "Dupliquer",
click: () => showCloneModal(),
color: "blue",
hidden: isConsumerCatalog,
},
{
text: "Supprimer",
click: () => showDeleteModal(),
color: "red",
hidden: isConsumerCatalog,
},
];
</script>

<TransitionWrapper>
Expand Down
3 changes: 1 addition & 2 deletions src/routes/products/CreateProduct.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
errorsHandler,
success: (res) => (initialValues.producer.notSubjectToVat = res.notSubjectToVat),
error: () => routerInstance.goTo(ProductRoutes.List),
errorNotification: "Un problème est survenu pendant la récupération des informations du produit.",
errorNotification: "Un problème est survenu pendant la récupération des informations du producteur.",
});
isLoading = false;
});
Expand All @@ -41,7 +41,6 @@
clearCache: [GET_PRODUCTS],
});
};
</script>

<TransitionWrapper>
Expand Down
5 changes: 3 additions & 2 deletions src/routes/products/ProductCatalogs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
};
$: invalidCatalogs = catalogs.length > 0 && catalogs.filter((c) => !c.wholeSalePricePerUnit).length > 0;
</script>

<table class="shadow w-full">
Expand Down Expand Up @@ -87,7 +86,9 @@
</td>
<td class="px-3 md:px-6 py-4 whitespace-no-wrap border-b border-gray-200 hidden lg:table-cell">
<div class="text-sm leading-5 font-medium truncate" style="max-width: 180px;">
{format(new Date(catalog.addedOn), "PP", { locale: fr })}
{catalog.addedOn
? format(new Date(catalog.addedOn), "PP", { locale: fr })
: format(new Date(), "PP", { locale: fr })}
</div>
</td>
<td class="px-3 md:px-6 py-4 whitespace-no-wrap border-b border-gray-200 hidden lg:table-cell">
Expand Down
76 changes: 38 additions & 38 deletions src/routes/products/ProductForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
},
});
};
</script>

<!-- svelte-ignore component-name-lowercase -->
Expand Down Expand Up @@ -160,47 +159,49 @@
<ErrorContainer field={$form.fields.name} />
</div>
</div>
<div class="form-control">
<div class="flex w-full">
<div class="w-full" class:hidden={product.producer?.notSubjectToVat}>
<label>TVA *</label>
<div
class="w-full text-lg justify-center button-group"
class:skeleton-box={$isLoading}
use:bindClass={{ form, name: "vat" }}
>
<button
on:click={() => selectVat(5.5)}
type="button"
class="text-sm md:text-base"
class:selected={product.vat === 5.5}
class:skeleton-box={$isLoading}
>
5,5%
</button>
<button
on:click={() => selectVat(10)}
type="button"
class="text-sm md:text-base"
class:selected={product.vat === 10}
class:skeleton-box={$isLoading}
>
10%
</button>
<button
on:click={() => selectVat(20)}
type="button"
class="text-sm md:text-base"
class:selected={product.vat === 20}
{#if !product.producer.notSubjectToVat}
<div class="form-control">
<div class="flex w-full">
<div class="w-full">
<label>TVA *</label>
<div
class="w-full text-lg justify-center button-group"
class:skeleton-box={$isLoading}
use:bindClass={{ form, name: "vat" }}
>
20%
</button>
<button
on:click={() => selectVat(5.5)}
type="button"
class="text-sm md:text-base"
class:selected={product.vat === 5.5}
class:skeleton-box={$isLoading}
>
5,5%
</button>
<button
on:click={() => selectVat(10)}
type="button"
class="text-sm md:text-base"
class:selected={product.vat === 10}
class:skeleton-box={$isLoading}
>
10%
</button>
<button
on:click={() => selectVat(20)}
type="button"
class="text-sm md:text-base"
class:selected={product.vat === 20}
class:skeleton-box={$isLoading}
>
20%
</button>
</div>
<ErrorContainer field={$form.fields.vat} />
</div>
<ErrorContainer field={$form.fields.vat} />
</div>
</div>
</div>
{/if}
<div class="form-control" style="display: block;">
<label>Labels</label>
<Toggle
Expand Down Expand Up @@ -425,5 +426,4 @@
--inputPadding: 18px;
--inputColor: #205164;
}
</style>
3 changes: 2 additions & 1 deletion src/routes/products/productForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export const validators = (product) => ({
"returnableId",
"description",
"picture",
"producer",
]),
name: {
value: product.name,
validators: ["required", "minLength:3"],
enabled: true,
},
vat: { value: product.vat, validators: ["required"], enabled: !product.notSubjectToVat },
vat: { value: product.vat, validators: ["required"], enabled: !product.producer.notSubjectToVat },
unit: {
value: product.unit,
validators: ["required"],
Expand Down

0 comments on commit 163afc9

Please sign in to comment.