-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Programs: new functionalities (#2270)
* type definitions * delete wiring * edit profile changes * clean update * remove unused constructs * programs container * programs cards dark mode * hide long program text * program page * remove extra details file * program details page * program skeleton * program and milestone container * temp milestones empty
- Loading branch information
Showing
27 changed files
with
547 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,19 @@ | ||
import { Except } from "type-fest"; | ||
import { OverrideProperties } from "type-fest"; | ||
import { Profile } from "services/types"; | ||
import { EndowmentProfileUpdate } from "types/aws"; | ||
import { Country } from "types/countries"; | ||
import { UNSDG_NUMS } from "types/lists"; | ||
import { ImgLink } from "components/ImgEditor"; | ||
import { OptionType } from "components/Selector"; | ||
|
||
type K = keyof EndowmentProfileUpdate; | ||
const _logo: K = "logo"; | ||
const _img: K = "image"; | ||
const _country: K = "hq_country"; | ||
const _activity_countries: K = "active_in_countries"; | ||
const _sdgs: K = "categories_sdgs"; | ||
const _general: K = "categories_general"; | ||
const _id: K = "id"; | ||
const _tier: K = "tier"; | ||
const _owner: K = "owner"; | ||
const _npo_type: K = "endow_designation"; | ||
const _contributor_verification_required: K = | ||
"contributor_verification_required"; | ||
|
||
export type FlatFormValues = Except< | ||
export type FV = OverrideProperties< | ||
EndowmentProfileUpdate, | ||
/** to flatten */ | ||
/** don't include for now */ | ||
| typeof _general | ||
/** not editable fields*/ | ||
| typeof _id | ||
| typeof _tier | ||
| typeof _owner | ||
| typeof _contributor_verification_required | ||
| "program" | ||
| "program_id" | ||
>; | ||
|
||
export type FormValues = Omit< | ||
FlatFormValues, | ||
| typeof _logo | ||
| typeof _img | ||
| typeof _country | ||
| typeof _sdgs | ||
| typeof _activity_countries | ||
| typeof _npo_type | ||
> & { | ||
[_npo_type]: OptionType<string>; | ||
[_logo]: ImgLink; | ||
[_img]: ImgLink; | ||
[_country]: Country; | ||
[_sdgs]: OptionType<UNSDG_NUMS>[]; | ||
[_activity_countries]: OptionType<string>[]; | ||
|
||
//meta | ||
type: Profile["type"]; | ||
initial: FlatFormValues; | ||
}; | ||
{ | ||
endow_designation: OptionType<string>; | ||
logo: ImgLink; | ||
image: ImgLink; | ||
hq_country: Country; | ||
sdgs: OptionType<UNSDG_NUMS>[]; | ||
active_in_countries: OptionType<string>[]; | ||
} | ||
> & { type: Profile["type"]; initial: EndowmentProfileUpdate }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Except } from "type-fest"; | ||
import { FV } from "./types"; | ||
import { Profile, endow } from "services/types"; | ||
import { EndowmentProfileUpdate } from "types/aws"; | ||
|
||
type RequiredFields = Pick<EndowmentProfileUpdate, "id" | "owner">; | ||
type Arg = | ||
| { | ||
type: "initial"; | ||
data: Profile & RequiredFields; | ||
} | ||
| { | ||
type: "final"; | ||
data: Except<FV, "id" | "owner" | "initial" | "type"> & RequiredFields; | ||
urls: { image: string; logo: string }; | ||
}; | ||
|
||
export function toProfileUpdate(arg: Arg): EndowmentProfileUpdate { | ||
if (arg.type === "initial") { | ||
const { data: d } = arg; | ||
return { | ||
id: d.id, | ||
owner: d.owner, | ||
active_in_countries: d.active_in_countries ?? [], | ||
categories: { sdgs: d.sdgs ?? [], general: [] }, | ||
charity_navigator_rating: "", | ||
contact_email: d.contact_email ?? "", | ||
contributor_verification_required: | ||
d.contributor_verification_required ?? false, | ||
endow_designation: endow(d) ? d.endow_designation : "", | ||
hq_country: d.hq_country ?? "", | ||
image: d.image ?? "", | ||
kyc_donors_only: d.kyc_donors_only ?? false, | ||
logo: d.logo ?? "", | ||
name: d.name ?? "", | ||
overview: d.overview ?? "", | ||
program: [], //program is updated in /create-program | ||
program_id: "", | ||
published: d.published ?? false, | ||
registration_number: d.registration_number ?? "", | ||
sdgs: d.sdgs ?? [], | ||
social_media_urls: { | ||
facebook: d.social_media_urls?.facebook ?? "", | ||
instagram: d.social_media_urls?.instagram ?? "", | ||
linkedin: d.social_media_urls?.linkedin ?? "", | ||
twitter: d.social_media_urls?.twitter ?? "", | ||
discord: d.social_media_urls?.discord ?? "", | ||
youtube: d.social_media_urls?.youtube ?? "", | ||
tiktok: d.social_media_urls?.tiktok ?? "", | ||
}, | ||
street_address: d.street_address ?? "", | ||
tagline: d.tagline ?? "", | ||
tier: 1, | ||
url: d.url ?? "", | ||
}; | ||
} | ||
|
||
const { data: fv, urls } = arg; | ||
return { | ||
...fv, | ||
program: [], //program is updated in /create-program | ||
image: urls.image, | ||
logo: urls.logo, | ||
hq_country: fv.hq_country.name, | ||
endow_designation: fv.endow_designation.value, | ||
sdgs: fv.sdgs.map((opt) => opt.value), | ||
active_in_countries: fv.active_in_countries.map((opt) => opt.value), | ||
}; | ||
} |
Oops, something went wrong.