Skip to content

Commit

Permalink
Fix styling and crashign date field
Browse files Browse the repository at this point in the history
  • Loading branch information
Wholteza committed Dec 23, 2023
1 parent fa44f7b commit 956b480
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/helpers/dynamic-object-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const mutatePropOnPath = <K>(
export const getValueOnPath = <T>(
dynamicObject: Record<string, never>,
propertyPath: string[]
): T => {
): T | null => {
const [key, ...rest] = propertyPath;
if (!rest.length) {
return dynamicObject[key] as T;
return dynamicObject[key] as T | null;
}
return getValueOnPath(dynamicObject[key], rest);
};
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-form/use-form-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("getFormValueBasedOnPropertyInformation", () => {
);

// assert
expect(result).toBe(expectedValue.toLocaleDateString());
expect(result).toBe(expectedValue.toLocaleDateString("sv-SE"));
expect(spy).toHaveBeenCalledWith(dynamicObject, information.propertyPath);
});
it("throws if type is anything but the implemented ones", () => {
Expand Down
16 changes: 10 additions & 6 deletions src/hooks/use-form/use-form-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ export const getFormValueBasedOnPropertyInformation = (
): string | number => {
switch (information.type) {
case "string":
return getValueOnPath<string>(dynamicObject, information.propertyPath);
return (
getValueOnPath<string>(dynamicObject, information.propertyPath) ?? ""
);
case "number":
return getValueOnPath<number>(dynamicObject, information.propertyPath);
return (
getValueOnPath<number>(dynamicObject, information.propertyPath) ?? 0
);
case "date":
return getValueOnPath<Date>(
dynamicObject,
information.propertyPath
).toLocaleDateString();
return (
getValueOnPath<Date>(dynamicObject, information.propertyPath) ??
new Date(Date.now())
).toLocaleDateString("se-SE");
default:
throw new Error(`field type ${information.type} is not implemented`);
}
Expand Down
5 changes: 2 additions & 3 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $color-primary-light: #B8B8FF;
$color-background: #F8F7FF;
$color-secondary-light: #FFEEDD;
$color-secondary: #FFD8BE;
$color-secondary-text: color-mix(in srgb, #FFD8BE 40%, black);

@mixin font-family {
font-family: 'Ubuntu Mono';
Expand All @@ -14,7 +15,6 @@ $color-secondary: #FFD8BE;

@mixin secondary-text-color{
color: $color-secondary;
filter: brightness(50%);
}

@mixin fade-in-animation {
Expand Down Expand Up @@ -75,7 +75,6 @@ body {
width: 100vw;
height: 100vh;
@media (min-width: 768px) {
width: 500px;
margin: 0 auto;
}
}
Expand Down Expand Up @@ -175,7 +174,7 @@ hr {
width: 100%;
}
label {
@include secondary-text-color();
color: $color-secondary-text;
font-weight: 600;
text-transform: capitalize;
position: relative;
Expand Down

0 comments on commit 956b480

Please sign in to comment.