Skip to content

Commit

Permalink
Type fixes and upgrade button fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fgatti675 committed Nov 30, 2023
1 parent 5db92bb commit e04d003
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export const PropertyForm = React.memo(
} as PropertyWithId;

const disabled = (Boolean(property && !editableProperty(property)) && !collectionEditable);
console.log("PropertyForm disabled", disabled)

const lastSubmittedProperty = useRef<OnPropertyChangedParams | undefined>(property ? {
id: propertyKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { EntityCollection } from "@firecms/firebase";
import { EntityCollection, makePropertiesEditable } from "@firecms/core";

export const blogCollectionTemplate:EntityCollection = {
path: "blog",
name: "Blog",
singularName: "Blog entry",
group: "Content",
icon: "article",
description: "A collection of blog entries",
defaultSize: "l",
properties: {
properties: makePropertiesEditable({
name: {
name: "Name",
validation: { required: true },
Expand Down Expand Up @@ -108,7 +107,7 @@ export const blogCollectionTemplate:EntityCollection = {
previewAsTag: true
}
}
},
}),
initialFilter: {
status: ["==", "published"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { EntityCollection } from "@firecms/core";
import { EntityCollection, makePropertiesEditable } from "@firecms/core";

export const productsCollectionTemplate: EntityCollection = {
path: "products",
name: "Products",
singularName: "Product",
group: "Main",
icon: "shopping_cart",
description: "List of the products currently sold in your shop",
properties: {
properties: makePropertiesEditable({
name: {
dataType: "string",
name: "Name",
Expand Down Expand Up @@ -84,6 +83,5 @@ export const productsCollectionTemplate: EntityCollection = {
name: "Added on",
autoValue: "on_create"
}
}

})
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { EntityCollection } from "@firecms/core";
import { EntityCollection, makePropertiesEditable } from "@firecms/core";

export const usersCollectionTemplate: EntityCollection = {
path: "users",
name: "Users",
singularName: "User",
group: "Main",
description: "Registered users in the app/web",
icon: "person",
properties: {
properties: makePropertiesEditable({
displayName: {
name: "Display name",
dataType: "string"
Expand All @@ -30,5 +29,5 @@ export const usersCollectionTemplate: EntityCollection = {
dataType: "string",
url: "image"
}
},
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export function PlansComparisonDialog({

export function PlansComparison() {

const { backendFirebaseApp } = useFireCMSBackend();
const authController = useAuthController();
const { backendFirebaseApp, backendUid } = useFireCMSBackend();

const { subscriptionPlan, projectId } = useProjectConfig();
const {
subscriptionPlan,
projectId
} = useProjectConfig();
if (!subscriptionPlan)
throw new Error("No subscription plan");

Expand All @@ -60,7 +62,6 @@ export function PlansComparison() {
getSubscriptionsForProject
} = useSubscriptionsForUserController({
firebaseApp: backendFirebaseApp,
userId: authController.user?.uid
});

const projectSubscriptions = getSubscriptionsForProject(projectId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import React, { useEffect, useState } from "react";
import { AutoAwesomeIcon, Card, Chip, CircularProgressCenter, cn, Typography, useBrowserTitleAndIcon } from "@firecms/core";
import {
AutoAwesomeIcon,
Card,
Chip,
CircularProgressCenter,
cn,
Typography,
useBrowserTitleAndIcon
} from "@firecms/core";
import { useSubscriptionsForUserController } from "../../hooks/useSubscriptionsForUserController";
import { ProductView } from "./ProductView";
import { getPriceString, getStatusText } from "../settings/common";
Expand All @@ -12,7 +20,7 @@ export function ProjectSubscriptionPlans({ uid }: {
uid: string
}) {

const { backendFirebaseApp, projectsApi } = useFireCMSBackend();
const { backendFirebaseApp } = useFireCMSBackend();
const { subscriptionPlan, projectId } = useProjectConfig();
if (!subscriptionPlan)
throw new Error("No subscription plan");
Expand All @@ -25,7 +33,6 @@ export function ProjectSubscriptionPlans({ uid }: {
getSubscriptionsForProject
} = useSubscriptionsForUserController({
firebaseApp: backendFirebaseApp,
userId: uid
});

const projectSubscriptions = getSubscriptionsForProject(projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
query,
where
} from "firebase/firestore";
import React, { useEffect, useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { Product, ProductPrice, ProductWithPrices, Subscription, SubscriptionType } from "../types/subscriptions";
import { useFireCMSBackend } from "./useFireCMSBackend";

export const SUBSCRIPTIONS_COLLECTION = "subscriptions";
export const PRODUCTS_COLLECTION = "products";
Expand All @@ -23,7 +24,6 @@ export const CHECKOUT_SESSION_COLLECTION = "checkout_sessions";
* @category Firebase
*/
export interface SubscriptionsForUserControllerProps {
userId?: string;
firebaseApp?: FirebaseApp;
}

Expand All @@ -43,9 +43,10 @@ export interface SubscriptionsController {
}

export function useSubscriptionsForUserController({
userId,
firebaseApp
}: SubscriptionsForUserControllerProps): SubscriptionsController {
firebaseApp
}: SubscriptionsForUserControllerProps): SubscriptionsController {

const { backendUid: userId } = useFireCMSBackend();

const firestoreRef = useRef<Firestore>();

Expand Down Expand Up @@ -221,7 +222,6 @@ export function useSubscriptionsForUserController({
}

const getSubscriptionsForProject = (projectId: string): Subscription[] => {
console.log("activeSubscriptions", activeSubscriptions)
return activeSubscriptions?.filter((subscription) => subscription.metadata.projectId === projectId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const docToCollection = (doc: DocumentSnapshot): PersistedCollection => {
}

export function prepareCollectionForPersistence<M extends { [Key: string]: CMSType }>(collection: PersistedCollection<M>) {
const properties = setUndefinedToDelete(removeFunctions(removeNonEditableProperties(collection.properties)));
const properties = setUndefinedToDelete(removeFunctions(collection.properties));
const newCollection: PersistedCollection = {
...removeUndefined(collection),
properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildCollection, buildProperty } from "@firecms/core";
import { buildCollection, buildProperty } from "@firecms/firebase";

// This is a demo collection with many of the available properties
// Note t
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Button, Entity, EntityValues, useSnackbarController } from "@firecms/core";
import { Button, Entity, EntityValues, useSnackbarController } from "@firecms/firebase";
import { Product } from "../types";

export function SampleEntityView({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { FieldHelperText, FieldProps, TextField, useModeController } from "@firecms/core";
import { FieldHelperText, FieldProps, TextField, useModeController } from "@firecms/firebase";

interface CustomColorTextFieldProps {
color: string
Expand Down
2 changes: 1 addition & 1 deletion packages/firecms_cli/templates/template_v3/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityReference } from "@firecms/core";
import { EntityReference } from "@firecms/firebase";

export type Product = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ export const EntityCollectionView = React.memo(
selectionEnabled={selectionEnabled}
collectionEntitiesCount={docsCount}
/>}
emptyComponent={canCreateEntities
emptyComponent={canCreateEntities && tableController.filterValues === undefined && tableController.sortBy === undefined
? <div className="flex flex-col items-center justify-center">
<Typography variant={"subtitle2"}>So empty...</Typography>
<Button
Expand All @@ -587,7 +587,7 @@ export const EntityCollectionView = React.memo(
Create your first entity
</Button>
</div>
: undefined
: <Typography variant={"label"}>No results with the applied filter/sort</Typography>
}
hoverRow={hoverRow}
inlineEditing={checkInlineEditing()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function makePropertiesEditable(properties: Properties) {
makePropertiesEditable(property.properties as Properties);
}
});
return properties;
}

export function makePropertiesNonEditable(properties: PropertiesOrBuilders): PropertiesOrBuilders {
Expand Down
10 changes: 8 additions & 2 deletions packages/firecms_core/src/core/util/property_utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from "react";

import { EntityCollection, PropertyConfig, PropertiesOrBuilders, PropertyOrBuilder, ResolvedProperty } from "../../types";
import {
EntityCollection,
PropertiesOrBuilders,
PropertyConfig,
PropertyOrBuilder,
ResolvedProperty
} from "../../types";
import { getFieldConfig } from "../form_field_configs";
import { isPropertyBuilder } from "./entities";
import { resolveProperty } from "./resolutions";
Expand Down Expand Up @@ -109,7 +115,7 @@ export function getBracketNotation(path: string): string {
export function getPropertiesWithPropertiesOrder<M extends Record<string, any>>(properties: PropertiesOrBuilders<M>, propertiesOrder?: Extract<keyof M, string>[]): PropertiesOrBuilders<M> {
if (!propertiesOrder) return properties;
const result: PropertiesOrBuilders<any> = {};
propertiesOrder.forEach(path => {
propertiesOrder.filter(Boolean).forEach(path => {
const property = getPropertyInPath(properties, path);
if (typeof property === "object" && property.dataType === "map" && property.properties) {
result[path] = {
Expand Down
3 changes: 1 addition & 2 deletions packages/firecms_core/src/types/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { User } from "./user";
/**
* Controller for retrieving the logged user or performing auth related operations.
* Note that if you are implementing your AuthController, you probably will want
* to do it as the result of a hook. Check {@link useFirebaseAuthController} code
* for an example.
* to do it as the result of a hook.
* @category Hooks and utilities
*/
export type AuthController<UserType extends User = User> = {
Expand Down

0 comments on commit e04d003

Please sign in to comment.