Merge branch 'dev' into ci-chromatic

This commit is contained in:
Nicholas Tindle
2025-02-03 07:13:53 -06:00
committed by GitHub
7 changed files with 36 additions and 18 deletions

View File

@@ -399,16 +399,12 @@ class UserCredit(UserCreditBase):
f"Top up amount must be at least 500 credits and multiple of 100 but is {amount}"
)
if not (user := await get_user_by_id(user_id)):
raise ValueError(f"User not found: {user_id}")
# Create checkout session
# https://docs.stripe.com/checkout/quickstart?client=react
# unit_amount param is always in the smallest currency unit (so cents for usd)
# which is equal to amount of credits
checkout_session = stripe.checkout.Session.create(
customer=await get_stripe_customer_id(user_id),
customer_email=user.email,
line_items=[
{
"price_data": {
@@ -422,13 +418,13 @@ class UserCredit(UserCreditBase):
}
],
mode="payment",
ui_mode="hosted",
payment_intent_data={"setup_future_usage": "off_session"},
saved_payment_method_options={"payment_method_save": "enabled"},
success_url=settings.config.platform_base_url
success_url=settings.config.frontend_base_url
+ "/marketplace/credits?topup=success",
cancel_url=settings.config.platform_base_url
cancel_url=settings.config.frontend_base_url
+ "/marketplace/credits?topup=cancel",
return_url=settings.config.platform_base_url + "/marketplace/credits",
)
await self._add_transaction(
@@ -602,8 +598,6 @@ def get_block_costs() -> dict[str, list[BlockCost]]:
async def get_stripe_customer_id(user_id: str) -> str:
user = await get_user_by_id(user_id)
if not user:
raise ValueError(f"User not found: {user_id}")
if user.stripeCustomerId:
return user.stripeCustomerId
@@ -624,8 +618,6 @@ async def set_auto_top_up(user_id: str, config: AutoTopUpConfig):
async def get_auto_top_up(user_id: str) -> AutoTopUpConfig:
user = await get_user_by_id(user_id)
if not user:
raise ValueError("Invalid user ID")
if not user.topUpConfig:
return AutoTopUpConfig(threshold=0, amount=0)

View File

@@ -34,9 +34,11 @@ async def get_or_create_user(user_data: dict) -> User:
return User.model_validate(user)
async def get_user_by_id(user_id: str) -> Optional[User]:
async def get_user_by_id(user_id: str) -> User:
user = await prisma.user.find_unique(where={"id": user_id})
return User.model_validate(user) if user else None
if not user:
raise ValueError(f"User not found with ID: {user_id}")
return User.model_validate(user)
async def create_default_user() -> Optional[User]:

View File

@@ -203,6 +203,9 @@ export default function CreditsPage() {
executions are happening.
</p>
<br />
{transactionHistory.transactions.length === 0 && (
<p className="text-neutral-600">No transactions found.</p>
)}
<Table
className={
transactionHistory.transactions.length === 0 ? "hidden" : ""

View File

@@ -25,10 +25,10 @@ export async function signup(values: z.infer<typeof signupFormSchema>) {
console.error("Error signing up", error);
// FIXME: supabase doesn't return the correct error message for this case
if (error.message.includes("P0001")) {
return "Please join our waitlist for your turn: https://agpt.co/waitlist";
return "not_allowed";
}
if (error.code?.includes("user_already_exists")) {
redirect("/login");
if (error.code === "user_already_exists") {
return "user_already_exists";
}
return error.message;
}

View File

@@ -34,6 +34,7 @@ export default function SignupPage() {
const [feedback, setFeedback] = useState<string | null>(null);
const router = useRouter();
const [isLoading, setIsLoading] = useState(false);
//TODO: Remove after closed beta
const [showWaitlistPrompt, setShowWaitlistPrompt] = useState(false);
const form = useForm<z.infer<typeof signupFormSchema>>({
@@ -58,10 +59,16 @@ export default function SignupPage() {
const error = await signup(data);
setIsLoading(false);
if (error) {
setShowWaitlistPrompt(true);
if (error === "user_already_exists") {
setFeedback("User with this email already exists");
return;
} else {
setShowWaitlistPrompt(true);
}
return;
}
setFeedback(null);
setShowWaitlistPrompt(false);
},
[form],
);

View File

@@ -662,6 +662,20 @@ export const NodeGenericInputField: FC<{
handleInputClick={handleInputClick}
/>
);
case "object":
return (
<NodeKeyValueInput
nodeId={nodeId}
selfKey={propKey}
schema={propSchema}
entries={currentValue}
errors={errors}
className={className}
displayName={displayName}
connections={connections}
handleInputChange={handleInputChange}
/>
);
default:
console.warn(
`Schema for '${propKey}' specifies unknown type:`,

View File

@@ -70,7 +70,7 @@ export type BlockIOObjectSubSchema = BlockIOSubSchemaMeta & {
export type BlockIOKVSubSchema = BlockIOSubSchemaMeta & {
type: "object";
additionalProperties: { type: "string" | "number" | "integer" };
additionalProperties?: { type: "string" | "number" | "integer" };
default?: { [key: string]: string | number };
secret?: boolean;
};