forked from aws-samples/amplify-next-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from cabcookie:add-manager-employee-relation
Chef/Mitarbeiter Beziehung
- Loading branch information
Showing
10 changed files
with
205 additions
and
119 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { PersonRelationship } from "@/helpers/person/relationships"; | ||
import { PlusCircle } from "lucide-react"; | ||
import { FC, useEffect, useState } from "react"; | ||
import { Button } from "../ui/button"; | ||
import RelationEdit from "./relations/relation-edit"; | ||
import RelationText from "./relations/relation-text"; | ||
|
||
interface PersonRelationshipShowEditProps { | ||
relationship?: PersonRelationship; | ||
updateRelationship: ( | ||
relationship: Partial<PersonRelationship> & { id: string } | ||
) => void; | ||
deleteRelationship?: (id: string) => Promise<string | undefined>; | ||
} | ||
|
||
export const emptyRelation = { | ||
id: "NEW", | ||
direction: "from", | ||
} as PersonRelationship; | ||
|
||
const PersonRelationshipShowEdit: FC<PersonRelationshipShowEditProps> = ({ | ||
updateRelationship, | ||
deleteRelationship, | ||
relationship = emptyRelation, | ||
}) => { | ||
const [isEditing, setIsEditing] = useState(false); | ||
const [relation, setRelation] = useState(relationship); | ||
|
||
useEffect(() => { | ||
setRelation(relationship); | ||
}, [relationship]); | ||
|
||
const saveChanges = async () => { | ||
await updateRelationship(relation); | ||
if (relationship.id === "NEW") setRelation(emptyRelation); | ||
setIsEditing(false); | ||
}; | ||
|
||
const abortChanges = () => { | ||
if (relationship.id === "NEW") setRelation(emptyRelation); | ||
setIsEditing(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
{relationship.id === "NEW" && !isEditing && ( | ||
<Button size="sm" className="gap-1" onClick={() => setIsEditing(true)}> | ||
<PlusCircle className="w-4 h-4" /> | ||
Relation | ||
</Button> | ||
)} | ||
|
||
{isEditing ? ( | ||
<RelationEdit | ||
relationship={relation} | ||
updateRelationship={setRelation} | ||
saveChanges={saveChanges} | ||
abortChanges={abortChanges} | ||
/> | ||
) : ( | ||
relationship.id !== "NEW" && ( | ||
<RelationText | ||
relationship={relationship} | ||
deleteRelation={() => deleteRelationship?.(relationship.id)} | ||
startEditing={() => setIsEditing(true)} | ||
/> | ||
) | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default PersonRelationshipShowEdit; |
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
Oops, something went wrong.