Skip to content

Commit

Permalink
feat: load json files into the DB and app uses DB (EddieHubCommunity#…
Browse files Browse the repository at this point in the history
…5765)

* feat: manage data with forms EddieHubCommunity#5575

* docs: manage data with forms

* fix: removed tabs for forms

* chore: refactored profile manage pages

* wip: loading json to db via api

* WIP: links next

* feat: save links + display in order

* fix: social links displaying

* feat: milestone json to db

* WIP: milestone with transactions

* feat: save milestones to profile

* feat: testomonials save + display

* fix: testimonial pinned totals on tab

* feat: events page

* fix: tags api

* fix: search + map for db

* feat: reload json secret

* fix: removed package changes

* fix: failing tests by reloading data

* feat: gh action to load profiles after deployment

* fix: using promise all for async

* fix: using promise all for all async

* fix: test tear down

* fix: removed form/api related files for another pr

* Rename vercel.yml to vercel-prod.yml

* ci: vercel deploy to beta

* ci: vercel beta domain

* ci: vercel beta alias domain

* ci: vercel beta alias

* ci: vercel beta sleep alias

* ci: vercel beta output tmp url

* fix: api secret

* fix: load files into db after deploy

* fix: parameter name in action

* fix: delete unused action

* docs: social links

* fix: only reload data on profile changes

* fix: socials not in links still saved

* fix: exclude stats in api response

* WIP

* fix: loading json files

* fix: load json data

* fix: debugging links

* fix: more profile checks

* chore: trigger deployment

* fix: beta domain for preview

* fix: vercel preview domain assign

* fix: onlyl deploy to preview after tests

* chore: comment to fix

* fix: testimonial pinned

* fix: split data load tests

* fix: profile location cache

* fix: deployment actions

* fix: user location for tests
  • Loading branch information
eddiejaoude authored May 19, 2023
1 parent 0fb38d8 commit bce1d99
Show file tree
Hide file tree
Showing 37 changed files with 1,076 additions and 565 deletions.
2 changes: 2 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ NODE_ENV="development"
GITHUB_ID=""
GITHUB_SECRET=""
NEXTAUTH_SECRET=""

LINKFREE_API_SECRET="development"
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ GITHUB_ID=""
GITHUB_SECRET=""
NEXTAUTH_SECRET="123456"
NEXTAUTH_URL="http://localhost:3000"

LINKFREE_API_SECRET="development"
20 changes: 20 additions & 0 deletions .github/workflows/load-data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Load profiles into DB
on:
workflow_dispatch:
workflow_run:
workflows: [Deploy to Vercel]

jobs:
load-data:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
data:
- 'data/**'
- name: load json files
if: steps.changes.outputs.data == 'true'
run: curl -f https://linkfree.io/api/system/reload?secret=${{ secrets.LINKFREE_API_SECRET }}
3 changes: 2 additions & 1 deletion .github/workflows/vercel.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Deploy releases to Vercel
name: Deploy to Vercel
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
workflow_dispatch:
release:
types: [published]
push:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ yarn-error.log*
# testing
/playwright-report/
/playwright/.cache/
data/_test-*.json
data/_test-*
test-results/

# storybook
Expand Down
54 changes: 26 additions & 28 deletions components/user/UserLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Alert from "@components/Alert";

export default function UserLinks({ BASE_URL, data }) {
const defaultBucket = "Others";
data.links = data.links?.map((link, i) => ({ id: i, ...link }));
const buckets = data.links?.reduce((acc, obj) => {
const group = obj.group || defaultBucket;
const curGroup = acc[group] ?? [];
Expand All @@ -16,34 +15,33 @@ export default function UserLinks({ BASE_URL, data }) {
{!data.links && <Alert type="info" message="No links found" />}
{data.links && (
<>
{data.links &&
Object.keys(buckets).map((name) => (
<div key={name} className="flex flex-col items-center w-full">
{Object.keys(buckets).length > 1 && (
<div
className="border-b border-primary-low pb-3 w-full mt-6 mb-3"
key={name}
>
<div className="-ml-2 -mt-2 flex flex-wrap items-baseline">
<h3 className="ml-2 mt-2 text-lg font-medium leading-6 dark:text-primary-low text-primary-high">
{name}
</h3>
<p className="ml-2 mt-1 truncate text-sm dark:text-primary-low-high text-primary-medium">
({buckets[name].length})
</p>
</div>
{Object.keys(buckets).map((name) => (
<div key={name} className="flex flex-col items-center w-full">
{Object.keys(buckets).length > 1 && (
<div
className="border-b border-primary-low pb-3 w-full mt-6 mb-3"
key={name}
>
<div className="-ml-2 -mt-2 flex flex-wrap items-baseline">
<h3 className="ml-2 mt-2 text-lg font-medium leading-6 dark:text-primary-low text-primary-high">
{name}
</h3>
<p className="ml-2 mt-1 truncate text-sm dark:text-primary-low-high text-primary-medium">
({buckets[name].length})
</p>
</div>
)}
{Object.values(buckets[name]).map((link) => (
<UserLink
BASE_URL={BASE_URL}
key={link.id}
link={link}
username={data.username}
/>
))}
</div>
))}
</div>
)}
{Object.values(buckets[name]).map((link) => (
<UserLink
BASE_URL={BASE_URL}
key={link._id}
link={link}
username={data.username}
/>
))}
</div>
))}
</>
)}
</>
Expand Down
5 changes: 4 additions & 1 deletion components/user/UserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default function UserPage({ data, BASE_URL }) {
{ name: "Testimonials", href: "#", current: false },
{ name: "Events", href: "#", current: false },
];
data.testimonials = data.testimonials.filter(
(testimonial) => testimonial.isPinned
);
let displayTabs = defaultTabs.flatMap((tab) => {
if (tab.name === "Milestones") {
if (data.milestones && data.milestones.length) {
Expand Down Expand Up @@ -54,7 +57,7 @@ export default function UserPage({ data, BASE_URL }) {

{tabs.find((tab) => tab.name === "Testimonials") &&
tabs.find((tab) => tab.name === "Testimonials").current && (
<UserTestimonials data={data} />
<UserTestimonials testimonials={data.testimonials} />
)}

{tabs.find((tab) => tab.name === "Events") &&
Expand Down
17 changes: 8 additions & 9 deletions components/user/UserProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ function UserProfile({ BASE_URL, data }) {
<div className="flex flex-col self-center gap-3">
<h1 className="text-3xl font-bold">{data.name}</h1>
<div className="flex md:w-full gap-2 mx-auto text-xl">
{data.socials &&
data.socials.map((social, index) => (
<UserSocial
social={social}
key={index}
BASE_URL={BASE_URL}
username={data.username}
/>
))}
{data.socials.map((social) => (
<UserSocial
social={social}
key={social._id}
BASE_URL={BASE_URL}
username={data.username}
/>
))}
</div>
</div>
</div>
Expand Down
10 changes: 4 additions & 6 deletions components/user/UserTestimonials.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import Link from "@components/Link";
import Alert from "@components/Alert";
import FallbackImage from "@components/FallbackImage";

export default function UserTestimonials({ data }) {
export default function UserTestimonials({ testimonials }) {
return (
<>
{!data.testimonials && (
<Alert type="info" message="No testimonials found" />
)}
{data.testimonials &&
data.testimonials.map((testimonial, key) => (
{!testimonials && <Alert type="info" message="No testimonials found" />}
{testimonials &&
testimonials.map((testimonial, key) => (
<div
className="flex flex-col sm:flex-row sm:gap-8 gap-2 sm:items-center text-sm dark:text-primary-low dark:bg-primary-medium text-primary-medium-low dark:border-none border-2 my-4 px-5 p-6 rounded-xl shadow-xl"
key={key}
Expand Down
10 changes: 8 additions & 2 deletions models/Link.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import mongoose from "mongoose";

const LinkSchema = new mongoose.Schema({
username: String,
username: String, // TODO: is this username needed after forms?
group: String,
name: String,
url: String,
icon: String,
isEnabled: Boolean,
isPinned: Boolean,
order: Number,
clicks: {
type: Number,
default: 0,
},
profile: {
type: mongoose.Schema.Types.ObjectId,
ref: "profile",
ref: "Profile",
},
});

Expand Down
3 changes: 2 additions & 1 deletion models/LinkStats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mongoose from "mongoose";

const linkStatsSchema = new mongoose.Schema({
// TODO: is username still needed after forms?
username: {
type: String,
required: true,
Expand All @@ -19,7 +20,7 @@ const linkStatsSchema = new mongoose.Schema({
},
profile: {
type: mongoose.Schema.Types.ObjectId,
ref: "profile",
ref: "Profile",
},
});

Expand Down
43 changes: 43 additions & 0 deletions models/Profile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import mongoose from "mongoose";

const ProfileSchema = new mongoose.Schema({
source: String,
username: {
type: String,
index: true,
},
name: String,
bio: String,
tags: {
type: [String],
default: [],
},
location: {
provided: String,
name: String,
Expand All @@ -20,6 +27,42 @@ const ProfileSchema = new mongoose.Schema({
default: [],
type: [{ type: mongoose.Schema.Types.ObjectId, ref: "Link" }],
},
milestones: [
{
url: String,
date: String,
isGoal: Boolean,
title: String,
icon: String,
description: String,
color: String,
order: Number,
},
],
testimonials: [
{
username: String,
title: String,
description: String,
date: String,
order: Number,
isPinned: Boolean,
},
],
events: [
{
isVirtual: Boolean,
color: String,
name: String,
description: String,
date: {
start: Date,
end: Date,
},
url: String,
order: Number,
},
],
});

module.exports =
Expand Down
3 changes: 2 additions & 1 deletion models/ProfileStats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mongoose from "mongoose";

const profileStatsSchema = new mongoose.Schema({
// TODO: is username still needed after forms?
username: {
type: String,
required: true,
Expand All @@ -15,7 +16,7 @@ const profileStatsSchema = new mongoose.Schema({
},
profile: {
type: mongoose.Schema.Types.ObjectId,
ref: "profile",
ref: "Profile",
},
});

Expand Down
2 changes: 1 addition & 1 deletion models/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const SessionSchema = new mongoose.Schema({
},
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: "user",
ref: "User",
},
});

Expand Down
31 changes: 0 additions & 31 deletions pages/api/discover/random.js

This file was deleted.

Loading

0 comments on commit bce1d99

Please sign in to comment.